X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/0eb72b526bf8bbb011551ecf019f604e17a534f1..093ec98e4a065acfc537ea22c08c337c115fe273:/sdk/python/arvados/retry.py diff --git a/sdk/python/arvados/retry.py b/sdk/python/arvados/retry.py index 3f62ab779f..ea4095930f 100644 --- a/sdk/python/arvados/retry.py +++ b/sdk/python/arvados/retry.py @@ -64,6 +64,7 @@ class RetryLoop(object): self.max_wait = max_wait self.next_start_time = 0 self.results = deque(maxlen=save_results) + self._attempts = 0 self._running = None self._success = None @@ -101,6 +102,7 @@ class RetryLoop(object): "recorded a loop result after the loop finished") self.results.append(result) self._success = self.check_result(result) + self._attempts += 1 def success(self): """Return the loop's end state. @@ -118,6 +120,19 @@ class RetryLoop(object): raise arvados.errors.AssertionError( "queried loop results before any were recorded") + def attempts(self): + """Return the number of attempts that have been made. + + Includes successes and failures.""" + return self._attempts + + def attempts_str(self): + """Human-readable attempts(): 'N attempts' or '1 attempt'""" + if self._attempts == 1: + return '1 attempt' + else: + return '{} attempts'.format(self._attempts) + def check_http_response_success(status_code): """Convert an HTTP status code to a loop control flag.