priority: high

status: open

title: Implement the payments retry backoff schedule

type: feature


current_content:
"""Backoff schedule for the payments retry path."""

def next_delay_ms(attempt, base_ms, max_ms):
    """Delay before retry number `attempt`, capped at max_ms."""
    raise NotImplementedError

note: hidden tests also run at verification time and are not shown

service: payments

spec:
Implement next_delay_ms(attempt, base_ms, max_ms).

Retries are numbered from 1: the delay before the FIRST retry is attempt=1.
The delay doubles with each attempt - base_ms for attempt 1, twice that for
attempt 2, four times for attempt 3 - and is capped at max_ms. The cap is a
ceiling on the returned value, not on the exponent.

attempt < 1 is not a retry and must raise ValueError.

visible_tests:
the delay doubles
delays are positive


content:
"""Backoff schedule for the payments retry path."""

def next_delay_ms(attempt, base_ms, max_ms):
    """Delay before retry number `attempt`, capped at max_ms."""
    if attempt < 1:
        raise ValueError('attempt must be >= 1')
    return min(base_ms * (2 ** (attempt - 1)), max_ms)

next: run_exercise_tests to execute it


note: all visible tests pass; hidden tests also ran and are not shown