-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
12 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import collections.abc | ||
import random | ||
|
||
DELAYS_PROVIDER = collections.abc.Callable[[int], float] | ||
DelaysProvider = collections.abc.Callable[[int], float] | ||
|
||
|
||
def constant_delays(*, delay: float = 0) -> DELAYS_PROVIDER: | ||
def constant_delays(*, delay: float = 0) -> DelaysProvider: | ||
return lambda _: delay | ||
|
||
|
||
def linear_backoff_delays( | ||
*, min_delay_seconds: float = 0, delay_multiplier: float = 0.05, jitter: float = 0.2 | ||
) -> DELAYS_PROVIDER: | ||
def _linear(attempt: int) -> float: | ||
) -> DelaysProvider: | ||
def __linear_backoff_delays(attempt: int) -> float: | ||
delay = min_delay_seconds + attempt * delay_multiplier | ||
jitter_amount = delay * random.random() * jitter | ||
if random.random() < 0.5: | ||
jitter_amount = -jitter_amount | ||
return delay + jitter_amount | ||
|
||
return _linear | ||
return __linear_backoff_delays | ||
|
||
|
||
linear_delays = linear_backoff_delays |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters