Intermediate
Full jitter with Retry-After
Write retry_delay_ms(attempt, base_ms, cap_ms, rand, retry_after_s=None). attempt counts from 1 (the number of the attempt that just failed) and rand is a number from 0 up to but not including 1.
The ceiling is min(cap_ms, base_ms * 2 ** (attempt - 1)). The jittered wait is int(rand * (ceiling + 1)). If retry_after_s is not None, never return less than retry_after_s * 1000.
What Check tests
- With rand 0.0 the wait is 0
- Attempt 1 with rand 0.5 waits 250 ms
- The ceiling doubles: attempt 3 with rand 0.5 waits 1000 ms
- The ceiling is capped: attempt 10 with rand 0.5 waits 4000 ms
- Retry-After wins when it is larger
- A smaller Retry-After does not shorten the jittered wait
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.