Retries, timeouts, and terminal failures
Attempts use exponential backoff with equal jitter, stop after five attempts, and time out after five minutes by default. The retry delay function fully controls scheduling and can be overridden globally or per method on either helper:
import { exponential, jitter } from 'durability/utils';
const durability = new Durability({
context: this.ctx,
handlers,
attemptTimeoutMs: 60_000,
retries: {
maxAttempts: 5,
delay: (attempt) => jitter(exponential(attempt)),
},
methods: {
resizeImage: {
attemptTimeoutMs: 10 * 60_000,
retries: {
maxAttempts: 2,
delay: (attempt) => exponential(attempt, 500, 30_000),
},
},
},
});Each attempt receives its own AbortSignal. A timed-out operation follows the normal retry policy; a timed-out named alarm is terminal unless retryTimeouts is set. A timeout ends the attempt: its concurrency permit is returned and the next attempt starts on schedule, whether or not the handler has stopped. Nothing can stop a running handler, so one that ignores abort keeps running beside the retry; its result is discarded, and once the retry has started its memoize calls reject. Stop work when the signal aborts, and make side effects safe to repeat.
Throw NonRetryableError to move work directly to failed without another attempt. Errors named NonRetryableError from other packages, such as cloudflare:workflows, are recognized too.