Skip to content

Commit

Permalink
Merge 588418a into 2ddb19f
Browse files Browse the repository at this point in the history
  • Loading branch information
asqui committed Sep 11, 2015
2 parents 2ddb19f + 588418a commit e4cea53
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions jira/resilientsession.py
Expand Up @@ -54,25 +54,31 @@ def __verb(self, verb, url, retry_data=None, **kwargs):
if isinstance(data, dict):
data = json.dumps(data)

counter = 0
while counter < self.max_retries:
counter += 1
retry_number = 0
while retry_number <= self.max_retries:
response = None
exception = None
try:
method = getattr(super(ResilientSession, self), verb.lower())\

r = method(url, **kwargs)
method = getattr(super(ResilientSession, self), verb.lower())
response = method(url, **kwargs)
except ConnectionError as e:
logging.warning(
"%s while doing %s %s [%s]" % (e, verb.upper(), url, kwargs))
r = e
if self.__recoverable(r, url, verb.upper(), counter):
exception = e
retry_number += 1
response_or_exception = response if response is not None else exception
if self.__recoverable(response_or_exception, url, verb.upper(), retry_number):
if retry_data:
# if data is a stream, we cannot just read again from it,
# retry_data() will give us a new stream with the data
kwargs['data'] = retry_data()
continue
raise_on_error(r, verb=verb, **kwargs)
return r
else:
break
if exception is not None:
raise exception
raise_on_error(response, verb=verb, **kwargs)
return response

def get(self, url, **kwargs):
return self.__verb('GET', url, **kwargs)
Expand Down

0 comments on commit e4cea53

Please sign in to comment.