X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e61df48303291900581ef4a64dcf97864598c5f4..59a972c831bc8f7cd4e896ed8e1c71277b97f04e:/sdk/python/arvados/retry.py diff --git a/sdk/python/arvados/retry.py b/sdk/python/arvados/retry.py index 168bd3910f..ea4095930f 100644 --- a/sdk/python/arvados/retry.py +++ b/sdk/python/arvados/retry.py @@ -1,4 +1,6 @@ -#!/usr/bin/env python +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 from builtins import range from builtins import object @@ -62,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 @@ -99,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. @@ -116,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.