Skip to content

Commit

Permalink
GitBook: [#147] No subject
Browse files Browse the repository at this point in the history
  • Loading branch information
manast authored and gitbook-bot committed Feb 3, 2023
1 parent fdf04be commit e625fbc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docs/gitbook/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* [Delayed](guide/jobs/delayed.md)
* [Repeatable](guide/jobs/repeatable.md)
* [Prioritized](guide/jobs/prioritized.md)
* [Removing job](guide/jobs/removing-job.md)
* [Removing jobs](guide/jobs/removing-job.md)
* [Stalled](guide/jobs/stalled.md)
* [Getters](guide/jobs/getters.md)
* [Flows](guide/flows/README.md)
Expand Down
29 changes: 13 additions & 16 deletions docs/gitbook/guide/jobs/delayed.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
# Delayed
The jobs added to a queue will normally be processed as quick as some worker is available for dispatching them. However, it is also possible to add a delay parameter so that jobs will wait at least that amount of time before being processed. Note that this does not guarantee that the job will be processed at that exact delayed time, it depends on how busy the queue is when the time has passed and how many other delayed jobs are scheduled at that exact time.

Delayed jobs are a special type of job that instead of being processed as fast as possible is placed on a special "delayed set" where it will wait until the delay time has passed and then it is processed as a regular job.
{% hint style="info" %}
Delayed jobs will only be processed if there is at least one [`QueueScheduler`](../queuescheduler.md) instance configured in the Queue.
{% endhint %}

In order to add delayed jobs to the queue, simply use the "delay" option with the amount of time in milliseconds that you want to delay the job with.
{% hint style="danger" %}
From BullMQ 2.0 and onwards, the QueueScheduler is not needed anymore.
{% endhint %}

Note that it is not guaranteed that the job will be processed at the exact delayed time specified, as it depends on how busy the workers are when the time has passed and how many other delayed jobs are scheduled at that exact time. In practice, however, the delay time is quite accurate in most cases.

This is an example of how to add delayed jobs to a queue:
This is an example on how to add delayed jobs:

```typescript
import { Queue } from 'bullmq';
import { Queue, QueueScheduler } from 'bullmq';

const myQueueScheduler = new QueueScheduler('Paint');
const myQueue = new Queue('Paint');

// Add a job that will be delayed by at least 5 seconds.
// Add a job that will be delayed at least 5 seconds.
await myQueue.add('house', { color: 'white' }, { delay: 5000 });
```

If you want to process the job after a specific point in time, just add the time remaining to that point in time. For example, let's say you want to process the job on the third of July 2035 at 10:30:

```typescript
const targetTime = new Date("03-07-2035 10:30");
const delay = (targetTime - new Date()).getTime();

await myQueue.add('house', { color: 'white' }, { delay });
```
## Read more:

- 💡 [Queue Scheduler API Reference](https://github.com/taskforcesh/bullmq/blob/v1.91.1/docs/gitbook/api/bullmq.queuescheduler.md)

0 comments on commit e625fbc

Please sign in to comment.