Added retry mechanism

This commit is contained in:
Rudi Grinberg 2012-10-31 11:45:22 -04:00
parent 474f5aba48
commit 4ef38cbc91
1 changed files with 8 additions and 0 deletions

View File

@ -88,6 +88,14 @@ class ApiRequest(object):
try: return json.loads(response)
except ValueError: return response
def retry(self, n):
"""Try to send request n times. If after n times it fails then
we finally raise exception"""
for i in range(0,n-1):
try: return self()
except Exception: pass
return self()
class RequestProvider(object):
""" Creates the available ApiRequest instance that can be read from
a config file """