diff --git a/slack_sdk/http_retry/__init__.py b/slack_sdk/http_retry/__init__.py index 6e684a01e..83c6315cf 100644 --- a/slack_sdk/http_retry/__init__.py +++ b/slack_sdk/http_retry/__init__.py @@ -4,7 +4,7 @@ RateLimitErrorRetryHandler, # noqa ) # noqa from .interval_calculator import RetryIntervalCalculator # noqa -from .builtin_interval_calculators import ( +from .builtin_interval_calculators import ( # noqa FixedValueRetryIntervalCalculator, # noqa BackoffRetryIntervalCalculator, # noqa ) # noqa @@ -16,11 +16,11 @@ connect_error_retry_handler = ConnectionErrorRetryHandler() # noqa rate_limit_error_retry_handler = RateLimitErrorRetryHandler() # noqa -default_retry_handlers = [ - connect_error_retry_handler, +default_retry_handlers = [ # noqa + connect_error_retry_handler, # noqa ] # noqa -all_builtin_retry_handlers = [ - connect_error_retry_handler, - rate_limit_error_retry_handler, +all_builtin_retry_handlers = [ # noqa + connect_error_retry_handler, # noqa + rate_limit_error_retry_handler, # noqa ] # noqa diff --git a/slack_sdk/http_retry/builtin_interval_calculators.py b/slack_sdk/http_retry/builtin_interval_calculators.py index 5f70c58ab..6354171f5 100644 --- a/slack_sdk/http_retry/builtin_interval_calculators.py +++ b/slack_sdk/http_retry/builtin_interval_calculators.py @@ -40,5 +40,5 @@ def __init__(self, backoff_factor: float = 0.5, jitter: Optional[Jitter] = None) def calculate_sleep_duration(self, current_attempt: int) -> float: interval = self.backoff_factor * (2 ** (current_attempt)) - sleep_duration = self.jitter.add_jitter_amount(interval) + sleep_duration = self.jitter.recalculate(interval) return sleep_duration diff --git a/slack_sdk/http_retry/jitter.py b/slack_sdk/http_retry/jitter.py index 5e2586c7b..852eaac60 100644 --- a/slack_sdk/http_retry/jitter.py +++ b/slack_sdk/http_retry/jitter.py @@ -4,8 +4,8 @@ class Jitter: """Jitter interface""" - def add_jitter_amount(self, duration: float) -> float: - """Adds a jitter amount to the given duration. + def recalculate(self, duration: float) -> float: + """Recalculate the given duration. see also: https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ Args: @@ -20,5 +20,5 @@ def add_jitter_amount(self, duration: float) -> float: class RandomJitter(Jitter): """Random jitter implementation""" - def add_jitter_amount(self, duration: float) -> float: + def recalculate(self, duration: float) -> float: return duration + random.random()