X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/9456885954b0bff02721bbb14da296be212efdc4..a9b9c6ff05e0268570b829bd62a6f683cf9f1d19:/sdk/python/arvados/retry.py diff --git a/sdk/python/arvados/retry.py b/sdk/python/arvados/retry.py index 2f2724333c..ea4095930f 100644 --- a/sdk/python/arvados/retry.py +++ b/sdk/python/arvados/retry.py @@ -1,3 +1,7 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 + from builtins import range from builtins import object import functools @@ -60,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 @@ -97,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. @@ -114,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.