Calculate the exponential backoff wait time.
(
factor: int,
retries: int,
maximum: int,
full_jitter: bool = False
)
| 446 | |
| 447 | |
| 448 | def get_exponential_backoff_interval( |
| 449 | factor: int, |
| 450 | retries: int, |
| 451 | maximum: int, |
| 452 | full_jitter: bool = False |
| 453 | ) -> int: |
| 454 | """Calculate the exponential backoff wait time.""" |
| 455 | # Will be zero if factor equals 0 |
| 456 | countdown = min(maximum, factor * (2 ** retries)) |
| 457 | # Full jitter according to |
| 458 | # https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ |
| 459 | if full_jitter: |
| 460 | countdown = random.randrange(countdown + 1) |
| 461 | # Adjust according to maximum wait time and account for negative values. |
| 462 | return max(0, countdown) |
no outgoing calls