Skip to content

Commit fa6ed76

Browse files
committed
Adding more retries to annotations update function
1 parent 6ec7ec4 commit fa6ed76

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

bigml/api_handlers/sourcehandler.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
LOGGER.addHandler(CONSOLE)
7777

7878
MAX_CHANGES = 5
79-
79+
MAX_RETRIES = 5
8080

8181
def compact_regions(regions):
8282
"""Returns the list of regions in the compact value used for updates """
@@ -573,18 +573,20 @@ def update_composite_annotations(self, source, images_file,
573573
offset * MAX_CHANGES: (offset + 1) * MAX_CHANGES]
574574
if new_batch:
575575
source = self.update_source(source,
576-
{"row_values": new_batch})
577-
if source["error"] is not None:
576+
{"row_values": new_batch})+
577+
counter = 0
578+
while source["error"] is not None and counter < MAX_RETRIES:
578579
# retrying in case update is temporarily unavailable
579-
time.sleep(1)
580+
counter += 1
581+
time.sleep(counter)
580582
source = self.get_source(source)
581583
self.ok(source)
582584
source = self.update_source(source,
583585
{"row_values": new_batch})
584-
if source["error"] is not None:
585-
LOGGER.error("WARNING: Some annotations were not"
586-
" updated (%s)",
587-
new_batch)
586+
if source["error"] is not None:
587+
LOGGER.error("WARNING: Some annotations were not"
588+
" updated (%s)",
589+
new_batch)
588590
if not self.ok(source):
589591
raise Exception(
590592
f"Failed to update {len(new_batch)} annotations.")

0 commit comments

Comments
 (0)