MCPcopy
hub / github.com/celery/celery / get_exponential_backoff_interval

Function get_exponential_backoff_interval

celery/utils/time.py:448–462  ·  view source on GitHub ↗

Calculate the exponential backoff wait time.

(
    factor: int,
    retries: int,
    maximum: int,
    full_jitter: bool = False
)

Source from the content-addressed store, hash-verified

446
447
448def 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)

Callers 9

test_with_jitterMethod · 0.90
test_without_jitterMethod · 0.90
test_bound_by_maximumMethod · 0.90
test_negative_valuesMethod · 0.90
store_resultMethod · 0.90
get_task_metaMethod · 0.90
prepare_modelsMethod · 0.90
runFunction · 0.90

Calls

no outgoing calls

Tested by 5

test_with_jitterMethod · 0.72
test_without_jitterMethod · 0.72
test_bound_by_maximumMethod · 0.72
test_negative_valuesMethod · 0.72