Skip to content

Commit acb34ab

Browse files
author
Craig Jellick
committed
Retry 409s for actions
1 parent 6e5031d commit acb34ab

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

gdapi.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,20 @@ def _put_and_retry(self, url, *args, **kw):
373373
raise e
374374
raise last_error
375375

376+
def _post_and_retry(self, url, *args, **kw):
377+
retries = kw.get('retries', 3)
378+
last_error = None
379+
for i in range(retries):
380+
try:
381+
return self._post(url, data=self._to_dict(*args, **kw))
382+
except ApiError as e:
383+
if e.error.status == 409:
384+
last_error = e
385+
time.sleep(.1)
386+
else:
387+
raise e
388+
raise last_error
389+
376390
def _validate_list(self, type, **kw):
377391
if not self._strict:
378392
return
@@ -412,7 +426,7 @@ def delete(self, *args):
412426

413427
def action(self, obj, action_name, *args, **kw):
414428
url = getattr(obj.actions, action_name)
415-
return self._post(url, data=self._to_dict(*args, **kw))
429+
return self._post_and_retry(url, *args, **kw)
416430

417431
def _is_list(self, obj):
418432
if isinstance(obj, list):

0 commit comments

Comments
 (0)