From 0a278b55b9fb974425662a40e3329ba6a4a0442e Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Thu, 29 Nov 2012 09:01:52 -0500 Subject: [PATCH] api: Only retry up to 10 times on connection errors. (imported from commit f395370120d5e7a635eec7b27e4d5ed0c48b774d) --- api/common.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/api/common.py b/api/common.py index 095b7900c2..b0ed7d812e 100644 --- a/api/common.py +++ b/api/common.py @@ -58,6 +58,7 @@ class HumbugAPI(object): request["email"] = self.email request["api-key"] = self.api_key request["client"] = self.client_name + failures = 0 for (key, val) in request.iteritems(): if not (isinstance(val, str) or isinstance(val, unicode)): @@ -69,7 +70,7 @@ class HumbugAPI(object): verify=True, timeout=55) # On 50x errors, try again after a short sleep - if str(res.status_code).startswith('5') and self.retry_on_errors: + if str(res.status_code).startswith('5') and self.retry_on_errors and failures < 10: if self.verbose: if not had_error_retry: sys.stdout.write("connection error %s -- retrying." % (res.status_code,)) @@ -79,6 +80,7 @@ class HumbugAPI(object): sys.stdout.write(".") sys.stdout.flush() time.sleep(1) + failures += 1 continue except (requests.exceptions.Timeout, requests.exceptions.SSLError) as e: # Timeouts are either a Timeout or an SSLError; we @@ -95,7 +97,7 @@ class HumbugAPI(object): return {'msg': "Connection error:\n%s" % traceback.format_exc(), "result": "connection-error"} except requests.exceptions.ConnectionError: - if self.retry_on_errors: + if self.retry_on_errors and failures < 10: if self.verbose: if not had_error_retry: sys.stdout.write("connection error -- retrying.") @@ -105,6 +107,7 @@ class HumbugAPI(object): sys.stdout.write(".") sys.stdout.flush() time.sleep(1) + failures += 1 continue return {'msg': "Connection error:\n%s" % traceback.format_exc(), "result": "connection-error"}