28 """Abstract base class for wait strategies."""
31 def __call__(self, retry_state:
"RetryCallState") -> float:
34 def __add__(self, other:
"wait_base") ->
"wait_combine":
48 """Wait strategy that waits a fixed amount of time between each retry."""
50 def __init__(self, wait: _utils.time_unit_type) ->
None:
53 def __call__(self, retry_state:
"RetryCallState") -> float:
58 """Wait strategy that doesn't wait at all before retrying."""
65 """Wait strategy that waits a random amount of time between min/max."""
71 def __call__(self, retry_state:
"RetryCallState") -> float:
76 """Combine several waiting strategies."""
78 def __init__(self, *strategies: wait_base) ->
None:
81 def __call__(self, retry_state:
"RetryCallState") -> float:
82 return sum(x(retry_state=retry_state)
for x
in self.
wait_funcs)
86 """Chain two or more waiting strategies.
88 If all strategies are exhausted, the very last strategy is used
93 @retry(wait=wait_chain(*[wait_fixed(1) for i in range(3)] +
94 [wait_fixed(2) for j in range(5)] +
95 [wait_fixed(5) for k in range(4)))
97 print("Wait 1s for 3 attempts, 2s for 5 attempts and 5s
101 def __init__(self, *strategies: wait_base) ->
None:
104 def __call__(self, retry_state:
"RetryCallState") -> float:
107 return wait_func(retry_state=retry_state)
111 """Wait an incremental amount of time after each attempt.
113 Starting at a starting value and incrementing by a value for each attempt
114 (and restricting the upper limit to some maximum value).
119 start: _utils.time_unit_type = 0,
127 def __call__(self, retry_state:
"RetryCallState") -> float:
129 return max(0, min(result, self.
max))
133 """Wait strategy that applies exponential backoff.
135 It allows for a customized multiplier and an ability to restrict the
136 upper and lower limits to some maximum and minimum value.
138 The intervals are fixed (i.e. there is no jitter), so this strategy is
139 suitable for balancing retries against latency when a required resource is
140 unavailable for an unknown duration, but *not* suitable for resolving
141 contention between multiple processes for a shared resource. Use
142 wait_random_exponential for the latter case.
147 multiplier: typing.Union[int, float] = 1,
157 def __call__(self, retry_state:
"RetryCallState") -> float:
161 except OverflowError:
167 """Random wait with exponentially widening window.
169 An exponential backoff strategy used to mediate contention between multiple
170 uncoordinated processes for a shared resource in distributed systems. This
171 is the sense in which "exponential backoff" is meant in e.g. Ethernet
172 networking, and corresponds to the "Full Jitter" algorithm described in
175 https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
177 Each retry occurs at a random time in a geometrically expanding interval.
178 It allows for a custom multiplier and an ability to restrict the upper
179 limit of the random interval to some maximum value.
183 wait_random_exponential(multiplier=0.5, # initial window 0.5s
184 max=60) # max 60s timeout
186 When waiting for an unavailable resource to become available again, as
187 opposed to trying to resolve contention for a shared resource, the
188 wait_exponential strategy (which uses a fixed interval) may be preferable.
192 def __call__(self, retry_state:
"RetryCallState") -> float:
198 """Wait strategy that applies exponential backoff and jitter.
200 It allows for a customized initial wait, maximum wait and jitter.
202 This implements the strategy described here:
203 https://cloud.google.com/storage/docs/retry-strategy
205 The wait time is min(initial * 2**n + random.uniform(0, jitter), maximum)
206 where n is the retry count.
221 def __call__(self, retry_state:
"RetryCallState") -> float:
225 result = self.
initial * exp + jitter
226 except OverflowError:
228 return max(0, min(result, self.
max))
"wait_combine" __add__(self, "wait_base" other)
typing.Union["wait_combine", "wait_base"] __radd__(self, "wait_base" other)
float __call__(self, "RetryCallState" retry_state)
float __call__(self, "RetryCallState" retry_state)
None __init__(self, *wait_base strategies)
float __call__(self, "RetryCallState" retry_state)
None __init__(self, *wait_base strategies)
float __call__(self, "RetryCallState" retry_state)
None __init__(self, float initial=1, float max=_utils.MAX_WAIT, float exp_base=2, float jitter=1)
float __call__(self, "RetryCallState" retry_state)
None __init__(self, typing.Union[int, float] multiplier=1, _utils.time_unit_type max=_utils.MAX_WAIT, typing.Union[int, float] exp_base=2, _utils.time_unit_type min=0)
float __call__(self, "RetryCallState" retry_state)
None __init__(self, _utils.time_unit_type wait)
None __init__(self, _utils.time_unit_type start=0, _utils.time_unit_type increment=100, _utils.time_unit_type max=_utils.MAX_WAIT)
float __call__(self, "RetryCallState" retry_state)
float __call__(self, "RetryCallState" retry_state)
float __call__(self, "RetryCallState" retry_state)
None __init__(self, _utils.time_unit_type min=0, _utils.time_unit_type max=1)