Skip to content

Commit

Permalink
Fix: transaction commits
Browse files Browse the repository at this point in the history
  • Loading branch information
cihanandac committed Mar 11, 2024
1 parent 611e4de commit 61fa513
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions backend/src/intk_vanabbe/src/intk_vanabbe/browser/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,7 @@ def sync_new_objects(self, date_from, start_range="0", end_range='5000'):
records = root.findall(".//record")

for record in records:
transaction.begin()
# Extract <dc_record> element
dc_record = record.find(".//dc_record")
log_to_file(f"{counter}. object")
Expand Down Expand Up @@ -1399,10 +1400,13 @@ def sync_new_objects(self, date_from, start_range="0", end_range='5000'):
import_one_exhibition(self, dc_record=dc_record, container=container, container_en=container_en, catalog=catalog)
else:
pass

transaction.commit()
except Exception as e:
log_to_file(
f"Error importing record: {record}. error = {e}"
)
transaction.abort()

counter = counter + 1

Expand Down Expand Up @@ -1447,11 +1451,9 @@ def serial_import(self):
log_to_file(f"Starting the sync function for the date after {date_from}")
log_to_file(f"total count of objects for update = {total_count}")

transaction.begin()
for offset in range(int(start_range), int(total_count), 500):
try:
self.sync_new_objects(start_range=offset, end_range=offset+500, date_from=date_from)
transaction.commit()
except Exception as e:
log_to_file(f"Failure processing batch {offset}-{offset+500}: {e}")

Expand Down

0 comments on commit 61fa513

Please sign in to comment.