Skip to content

Commit

Permalink
Merge pull request #8 from cjellick/action-retries
Browse files Browse the repository at this point in the history
Retry 409s for actions
  • Loading branch information
ibuildthecloud authored Jan 16, 2017
2 parents 6e5031d + acb34ab commit 31d7450
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion gdapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,20 @@ def _put_and_retry(self, url, *args, **kw):
raise e
raise last_error

def _post_and_retry(self, url, *args, **kw):
retries = kw.get('retries', 3)
last_error = None
for i in range(retries):
try:
return self._post(url, data=self._to_dict(*args, **kw))
except ApiError as e:
if e.error.status == 409:
last_error = e
time.sleep(.1)
else:
raise e
raise last_error

def _validate_list(self, type, **kw):
if not self._strict:
return
Expand Down Expand Up @@ -412,7 +426,7 @@ def delete(self, *args):

def action(self, obj, action_name, *args, **kw):
url = getattr(obj.actions, action_name)
return self._post(url, data=self._to_dict(*args, **kw))
return self._post_and_retry(url, *args, **kw)

def _is_list(self, obj):
if isinstance(obj, list):
Expand Down

0 comments on commit 31d7450

Please sign in to comment.