30/34
Part 8 of 8 · Follow-upsLearn and do

Retry only what might succeed next time

A timeout leaves you a choice: try the call again, or give up on it.

Retry a timeout, a dropped connection or a busy server. Don't retry a ValueError from a bad step or bad data, which fails the same way every time.

Cap the attempts. Wait longer each time, with some randomness, so retries don't arrive together. Record which tables gave up.

The steps here are pure functions of their input, so running one twice is safe. A step that writes somewhere has to be written so that doing it twice does no harm.

In the editor, write retry(fn, attempts, retry_on), the capped retry this step describes. It retries only the exception types in retry_on. flaky is a test function that times out twice and then answers.