Commit c7837b0e authored by Josh Roesslein's avatar Josh Roesslein
Browse files

Limit retries to 500,502,503 errors by default. Developer can also supply what...

Limit retries to 500,502,503 errors by default. Developer can also supply what status codes to retry on.
parent b768e76c
...@@ -16,7 +16,7 @@ class API(object): ...@@ -16,7 +16,7 @@ class API(object):
def __init__(self, auth_handler=None, host='twitter.com', cache=None, def __init__(self, auth_handler=None, host='twitter.com', cache=None,
secure=False, api_root='', validate=True, secure=False, api_root='', validate=True,
retry_count=0, retry_delay=0): retry_count=0, retry_delay=0, retry_errors=[500,502,503]):
# you may access these freely # you may access these freely
self.auth_handler = auth_handler self.auth_handler = auth_handler
self.host = host self.host = host
...@@ -26,6 +26,7 @@ class API(object): ...@@ -26,6 +26,7 @@ class API(object):
self.validate = validate self.validate = validate
self.retry_count = retry_count self.retry_count = retry_count
self.retry_delay = retry_delay self.retry_delay = retry_delay
self.retry_errors = retry_errors
# not a good idea to touch these # not a good idea to touch these
self._username = None self._username = None
......
...@@ -35,6 +35,7 @@ def bind_api(path, parser, allowed_param=[], method='GET', require_auth=False, ...@@ -35,6 +35,7 @@ def bind_api(path, parser, allowed_param=[], method='GET', require_auth=False,
# check for retry request parameters # check for retry request parameters
retry_count = kargs.pop('retry_count', api.retry_count) retry_count = kargs.pop('retry_count', api.retry_count)
retry_delay = kargs.pop('retry_delay', api.retry_delay) retry_delay = kargs.pop('retry_delay', api.retry_delay)
retry_errors = kargs.pop('retry_errors', api.retry_errors)
# check for headers # check for headers
headers = kargs.pop('headers', {}) headers = kargs.pop('headers', {})
...@@ -110,8 +111,8 @@ def bind_api(path, parser, allowed_param=[], method='GET', require_auth=False, ...@@ -110,8 +111,8 @@ def bind_api(path, parser, allowed_param=[], method='GET', require_auth=False,
# Get response # Get response
resp = conn.getresponse() resp = conn.getresponse()
# If request was successful, quit the loop # Exit request loop if non-retry error code
if resp.status == 200: if resp.status not in retry_errors:
break break
# Sleep before retrying request again # Sleep before retrying request again
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment