Overview
The Backoffs class provides built-in backoff strategies for job retries and utilities for normalizing backoff options.Built-in Strategies
fixed
Returns a fixed delay with optional jitter.The fixed delay in milliseconds
Jitter factor (0-1) to randomize delay
Example
exponential
Returns an exponentially increasing delay with optional jitter.The base delay in milliseconds
Jitter factor (0-1) to randomize delay
delay * 2^(attemptsMade - 1)
Example
Static Methods
normalize
Normalizes a backoff value to BackoffOptions.Backoff configuration (number for fixed delay or BackoffOptions object)
calculate
Calculates the delay for a given attempt.Backoff configuration
Number of attempts already made
The error that caused the failure
The job being retried
Custom backoff strategy function
BackoffOptions
Custom Backoff Strategy
You can implement a custom backoff strategy:Jitter Calculation
When jitter is specified, the actual delay is randomized:delay: 1000 and jitter: 0.2:
- Minimum delay: 800ms
- Maximum delay: 1200ms
