/** * How long to wait before trying again. * * Exponential, capped, and jittered, for the reasons the rest of this repo * gives in `@persistmemory/async`: * * exponential a cause that has not cleared in 200ms may clear in two * seconds; hammering it every 200ms spends the attempts faster * without giving it time to recover. * * capped unbounded doubling reaches minutes, and a caller waiting * inside one function call cannot tell that from a hang. * * jittered the one that gets skipped, and the one that matters most. An * outage fails every in-flight request at once; without jitter * every client waits exactly two seconds and retries in the * same millisecond, so the recovering service is hit by the * whole fleet and knocked over again. The retry storm is caused * by the retry policy. * * Duplicated here rather than imported from `@persistmemory/async` on purpose: * this package is published to npm and installed by people who have no reason * to pull in a queue runtime, a Redis client and a dead-letter store to make * an HTTP request. */ export interface BackoffOptions { readonly baseMs?: number; readonly maxMs?: number; readonly factor?: number; /** 0 = none, 1 = full. Full is the right default; see below. */ readonly jitter?: number; /** Injected so a test is not at the mercy of the random number generator. */ readonly random?: () => number; } /** * Short by server standards. * * A queue worker can afford to come back in a minute. A caller is blocked * inside `await client.search(...)` and has a user watching, so the whole * retry budget has to fit inside a request timeout rather than outlast it. */ export declare const DEFAULT_BACKOFF: { readonly baseMs: 250; readonly maxMs: 8000; readonly factor: 2; readonly jitter: 1; }; /** * The delay before attempt `attempt` (1-based). * * FULL jitter by default - a random point in [0, ceiling] rather than * ceiling plus or minus a wobble. It sounds worse and measures better: * partial jitter leaves the retries clustered around the same instant, which * is the thing that overwhelms a service coming back up. */ export declare function backoffMs(attempt: number, options?: BackoffOptions): number; /** * The delay to actually use, honouring what the server asked for. * * `Retry-After` is taken as a FLOOR, not verbatim. Verbatim would let a * one-second hint on the fifth consecutive 429 undo the backoff entirely and * put us straight back into the limit; ignoring it would have us retry before * the window resets and spend an attempt learning what we were already told. * * A server asking for LONGER than our cap is believed. The cap exists to stop * our own growth running away, not to overrule a service that has told us * when it will be ready. */ export declare function delayFor(args: { attempt: number; retryAfterSeconds?: number; options?: BackoffOptions; }): number;