X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/09cbdc3074b3f1e69c9c537875146f6da0a6ed8f..ab9e90bcdc6db96aed24c9362efa87ce99e1f923:/sdk/python/arvados/retry.py?ds=sidebyside diff --git a/sdk/python/arvados/retry.py b/sdk/python/arvados/retry.py index e93624a5d1..ea8a6f65af 100644 --- a/sdk/python/arvados/retry.py +++ b/sdk/python/arvados/retry.py @@ -27,7 +27,7 @@ from collections import deque import arvados.errors _HTTP_SUCCESSES = set(range(200, 300)) -_HTTP_CAN_RETRY = set([408, 409, 422, 423, 500, 502, 503, 504]) +_HTTP_CAN_RETRY = set([408, 409, 423, 500, 502, 503, 504]) class RetryLoop(object): """Coordinate limited retries of code. @@ -49,34 +49,29 @@ class RetryLoop(object): Arguments: - num_retries: int - : The maximum number of times to retry the loop if it - doesn't succeed. This means the loop body could run at most + * num_retries: int --- The maximum number of times to retry the loop if + it doesn't succeed. This means the loop body could run at most `num_retries + 1` times. - success_check: Callable - : This is a function that will be called each - time the loop saves a result. The function should return - `True` if the result indicates the code succeeded, `False` if it - represents a permanent failure, and `None` if it represents a - temporary failure. If no function is provided, the loop will - end after any result is saved. - - backoff_start: float - : The number of seconds that must pass before the loop's second - iteration. Default 0, which disables all waiting. - - backoff_growth: float - : The wait time multiplier after each iteration. - Default 2 (i.e., double the wait time each time). - - save_results: int - : Specify a number to store that many saved results from the loop. - These are available through the `results` attribute, oldest first. - Default 1. - - max_wait: float - : Maximum number of seconds to wait between retries. Default 60. + * success_check: Callable --- This is a function that will be called + each time the loop saves a result. The function should return `True` + if the result indicates the code succeeded, `False` if it represents a + permanent failure, and `None` if it represents a temporary failure. + If no function is provided, the loop will end after any result is + saved. + + * backoff_start: float --- The number of seconds that must pass before + the loop's second iteration. Default 0, which disables all waiting. + + * backoff_growth: float --- The wait time multiplier after each + iteration. Default 2 (i.e., double the wait time each time). + + * save_results: int --- Specify a number to store that many saved + results from the loop. These are available through the `results` + attribute, oldest first. Default 1. + + * max_wait: float --- Maximum number of seconds to wait between + retries. Default 60. """ def __init__(self, num_retries, success_check=lambda r: True, backoff_start=0, backoff_growth=2, save_results=1, @@ -138,8 +133,8 @@ class RetryLoop(object): Arguments: - result: Any - : The result from this loop attempt to check and save. + * result: Any --- The result from this loop attempt to check and + save. """ if not self.running(): raise arvados.errors.AssertionError( @@ -200,10 +195,6 @@ def check_http_response_success(status_code): * Any 2xx result returns `True`. * A select few status codes, or any malformed responses, return `None`. - 422 Unprocessable Entity is in this category. This may not meet the - letter of the HTTP specification, but the Arvados API server will - use it for various server-side problems like database connection - errors. * Everything else returns `False`. Note that this includes 1xx and 3xx status codes. They don't indicate success, and you can't @@ -211,8 +202,7 @@ def check_http_response_success(status_code): Arguments: - status_code: int - : A numeric HTTP response code + * status_code: int --- A numeric HTTP response code """ if status_code in _HTTP_SUCCESSES: return True @@ -233,8 +223,8 @@ def retry_method(orig_func): Arguments: - orig_func: Callable - : A class or instance method that accepts a `num_retries` keyword argument + * orig_func: Callable --- A class or instance method that accepts a + `num_retries` keyword argument """ @functools.wraps(orig_func) def num_retries_setter(self, *args, **kwargs):