From acb34abfc9f271dd16b56494c3777054b98f9a1e Mon Sep 17 00:00:00 2001 From: Craig Jellick Date: Mon, 16 Jan 2017 14:15:46 -0700 Subject: [PATCH] Retry 409s for actions --- gdapi.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gdapi.py b/gdapi.py index 1982c77..21bc00a 100755 --- a/gdapi.py +++ b/gdapi.py @@ -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 @@ -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):