@@ -9,20 +9,24 @@ class Backoff(Iterator[float]):
99 described in this post: https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
1010
1111 Args:
12- multiplier (float): No description.
13- max_wait (float): No description.
14- base (int): No description."""
12+ multiplier (float): Scales the exponential curve; the cap after n attempts is ``multiplier * base**n``.
13+ max_wait (float): Hard ceiling on the sampled wait in seconds.
14+ base (int): Exponential base; 2 gives classic doubling behaviour.
15+ min_wait (float): Lower bound of the uniform sample, useful when an immediate retry is undesirable."""
1516
16- def __init__ (self , multiplier : float = 0.5 , max_wait : float = 60.0 , base : int = 2 ) -> None :
17+ def __init__ (self , multiplier : float = 0.5 , max_wait : float = 60.0 , base : int = 2 , min_wait : float = 0.0 ) -> None :
1718 self ._multiplier = multiplier
1819 self ._max_wait = max_wait
1920 self ._base = base
21+ self ._min_wait = min_wait
2022 self ._past_attempts = 0
2123
2224 def __next__ (self ) -> float :
2325 # 100 is an arbitrary limit at which point most sensible parameters are likely to
2426 # be capped by max anyway.
25- wait = uniform (0 , min (self ._multiplier * (self ._base ** min (100 , self ._past_attempts )), self ._max_wait ))
27+ base = self ._multiplier * (self ._base ** min (100 , self ._past_attempts ))
28+ cap = max (self ._min_wait , min (base , self ._max_wait ))
29+ wait = uniform (self ._min_wait , cap )
2630 self ._past_attempts += 1
2731 return wait
2832
0 commit comments