From 268b803a4ef5a59e8c4664cddc50a50b1aea2dd8 Mon Sep 17 00:00:00 2001 From: Sourabh Bajaj Date: Mon, 21 Nov 2016 11:28:56 -0800 Subject: [PATCH 1/2] Add missing fields to the retry decorator --- sdks/python/apache_beam/utils/retry.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sdks/python/apache_beam/utils/retry.py b/sdks/python/apache_beam/utils/retry.py index b3016fd782ab..5a9cabf87fb3 100644 --- a/sdks/python/apache_beam/utils/retry.py +++ b/sdks/python/apache_beam/utils/retry.py @@ -117,7 +117,7 @@ def no_retries(fun): def with_exponential_backoff( num_retries=16, initial_delay_secs=5.0, logger=logging.warning, retry_filter=retry_on_server_errors_filter, - clock=Clock(), fuzz=True): + clock=Clock(), fuzz=True, factor=2, max_delay_secs=60 * 60 * 4): """Decorator with arguments that control the retry logic. Args: @@ -155,7 +155,8 @@ def real_decorator(fun): def wrapper(*args, **kwargs): retry_intervals = iter( FuzzedExponentialIntervals( - initial_delay_secs, num_retries, fuzz=0.5 if fuzz else 0)) + initial_delay_secs, num_retries, factor, + fuzz=0.5 if fuzz else 0, max_delay_secs=max_delay_secs)) while True: try: return fun(*args, **kwargs) From 923958a0c1e059c7554854d4f95a471cf947bc6b Mon Sep 17 00:00:00 2001 From: Sourabh Bajaj Date: Mon, 21 Nov 2016 12:16:13 -0800 Subject: [PATCH 2/2] Update documentation --- sdks/python/apache_beam/utils/retry.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sdks/python/apache_beam/utils/retry.py b/sdks/python/apache_beam/utils/retry.py index 5a9cabf87fb3..3874c7aa976f 100644 --- a/sdks/python/apache_beam/utils/retry.py +++ b/sdks/python/apache_beam/utils/retry.py @@ -134,6 +134,11 @@ def with_exponential_backoff( use time.sleep(). fuzz: True if the delay should be fuzzed (default). During testing False can be used so that the delays are not randomized. + factor: The exponential factor to use on subsequent retries. + Default is 2 (doubling). + max_delay_sec: Maximum delay (in seconds). After this limit is reached, + further tries use max_delay_sec instead of exponentially increasing + the time. Defaults to 4 hours. Returns: As per Python decorators with arguments pattern returns a decorator