Options to enable and control a BackoffStrategy.

The delay between retries is multiplied by backoffGrowth after each failure. Delay therefore has an exponent of n for the nth repetition.

Delay is calculated to be approximately backoffMs * Math.pow(backoffFactorGrowth, n). This delay is optionally randomised by a jitter factor and/or limited by backoffMaxExponent.

interface BackoffOptions {
    backoffGrowth?: number;
    backoffJitter?: number;
    backoffMaxExponent?: number;
    backoffMs: number;
    retryAllowed?: ((error) => boolean);
}

Properties

backoffGrowth?: number

The initial delay grows by this proportion after each failure. By default backoffGrowth is 2.0 meaning the first delay is 1.0 x backoffMs, the second is 2.0 x backoffMs, the third is 4.0 x backoffMs Set to 1.0 to eliminate exponential growth in the delay. A value of less than 1.0 is considered invalid and will throw an exception.

backoffJitter?: number

When scheduling an exponential delay, it is adjusted by a random jitter -- a proportion of the calculated delay between -backoffJitter and +backoffJitter.

The default is 0.1 meaning the actual delay falls between 90% and 110% of the exponential delay. This helps to avoid multiple independent schedulers synchronizing their retries even when the initial failures were synchronized. Set to 0 for no jitter.

backoffMaxExponent?: number

A ceiling for the backoff exponent that prevents delays becoming astronomical. Default is 10 meaning the scheduled delay is constant after the 10th failure. Set to Infinity for no limit. A value of less than 1.0 is considered invalid and will throw an exception.

backoffMs: number

The delay before the first retry. Subsequent retries are scheduled by multiplying this millisecond delay by a constant factor.

There is no default value. Setting a backoffMs activates the backoff strategy. If backoffMs is not present, no backoff strategy will be launched and all other backoffXXX options should be omitted.

retryAllowed?: ((error) => boolean)

Predicate to determine if a thrown error allows a retry. If retries or backoffMs is set, but retryAllowed is omitted then jobs are retried after all errors.

Type declaration

    • (error): boolean
    • Parameters

      • error: unknown

      Returns boolean