Skip to main content

Overview

Delayed jobs are placed into a special “delayed set” instead of being processed immediately. After the delay time has passed, the job moves to the waiting queue and is processed as a regular job.
The delay time is quite accurate in most cases, but it’s not guaranteed to be exact. Processing depends on worker availability and the number of other delayed jobs scheduled at that time.

Basic Usage

Use the delay option with the amount of time in milliseconds to delay the job:
From src/classes/job.ts:88:

Scheduling for a Specific Time

To process a job at a specific point in time, calculate the delay from now:

Change Delay

You can reschedule a delayed job after inserting it using the changeDelay method:
From src/classes/job.ts:1048:
Only jobs currently in the delayed state can have their delay changed. Attempting to change the delay of a job in another state will throw an error.

Delayed Job Lifecycle

When a delayed job is added:
  1. Job is added to the “delayed” sorted set with the timestamp when it should be processed
  2. Workers periodically check for delayed jobs whose timestamp has passed
  3. When the delay expires, the job moves to the “wait” or “prioritized” list
  4. The job is then processed normally
From src/classes/job.ts:985:

Move to Delayed Programmatically

You can manually move an active job to the delayed state:
From src/classes/job.ts:1413:

Job Options Interface

From src/interfaces/base-job-options.ts:21:

Best Practices

Sync Clocks

For accurate delays, ensure worker and producer clocks are synchronized (use NTP).

Avoid Long Delays

For delays longer than a few hours, consider using repeatable jobs or external schedulers.

Monitor Delayed Jobs

Use getDelayed() to monitor the number of delayed jobs and their timestamps.

Handle Clock Skew

Be aware that clock differences between servers can affect delay accuracy.

Common Use Cases

Automatically retry failed jobs after a delay:
Send notifications at a specific time:
Delay jobs to implement rate limiting:

API Reference

View the Change Delay API Reference