Skip to content

Commit

Permalink
Merge pull request #7 from cjellick/retry-update
Browse files Browse the repository at this point in the history
Add retry to update
  • Loading branch information
ibuildthecloud authored Oct 26, 2016
2 parents 4a0c0e2 + 5a49ed4 commit 6e5031d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions gdapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,25 @@ def update_by_id(self, type, id, *args, **kw):
else:
url = '/'.join([url, id])

return self._put(url, data=self._to_dict(*args, **kw))
return self._put_and_retry(url, *args, **kw)

def update(self, obj, *args, **kw):
url = obj.links.self
return self._put(url, data=self._to_dict(*args, **kw))
return self._put_and_retry(url, *args, **kw)

def _put_and_retry(self, url, *args, **kw):
retries = kw.get('retries', 3)
last_error = None
for i in range(retries):
try:
return self._put(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:
Expand Down

0 comments on commit 6e5031d

Please sign in to comment.