EasyReliabilityPython 3

Retry Backoff Planner

Plan retry delays with capped exponential backoff and explicit retryable error classes.

25m3 sample tests5 hidden tests

Implement deterministic retry-delay logic for transient failures.

Requirements

  • Define RetryPolicy(max_attempts, base_delay, max_delay, retryable_errors).
  • next_delay(attempt, error_code) returns the delay before the next try.
  • attempt is the failed attempt number, starting at 1 for the first failure.
  • Return None if the error isn't retryable.
  • Return None if attempt >= max_attempts.
  • Otherwise return exponential backoff: base_delay * 2 ** max(0, attempt - 1). The max(0, …) clamp keeps the exponent non-negative if attempt < 1 (e.g. attempt=0 uses exponent 0 and returns base_delay before the cap).
  • Cap the delay at max_delay.

Example

python
1policy = RetryPolicy(4, 0.5, 5, {"timeout"}) 2assert policy.next_delay(1, "timeout") == 0.5 3assert policy.next_delay(4, "timeout") is None

Constraints

  • Don't use randomness.
  • Keep decisions deterministic and testable.
  • Treat unknown errors as non-retryable.

Editor