Skip to content

Commit

Permalink
docs(jobs): add debouncing section
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Jul 22, 2024
1 parent 43a4cdb commit d9f1c1d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/gitbook/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* [LIFO](guide/jobs/lifo.md)
* [Job Ids](guide/jobs/job-ids.md)
* [Job Data](guide/jobs/job-data.md)
* [Debouncing](guide/jobs/debouncing.md)
* [Delayed](guide/jobs/delayed.md)
* [Repeatable](guide/jobs/repeatable.md)
* [Prioritized](guide/jobs/prioritized.md)
Expand Down
24 changes: 24 additions & 0 deletions docs/gitbook/guide/jobs/debouncing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Debouncing

Debouncing a job implies delaying and deduplicating it.

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

const myQueue = new Queue('Paint');

// Add a job that will be debounced for 5 seconds.
await myQueue.add('house', { color: 'white' }, { debouncedId: 'customValue', delay: 5000 });
```

For the next 5 seconds, after adding this job, next jobs added with same **debouncedId** will be ignored and a _debounced_ event will be triggered by our QueueEvent class.

Note that apart of passing a delay value, you must provide a debouncedId that should represent your job. You can hash your entire job data or a subset of attributes for creating a debouncedId.

{% hint style="warning" %}
Passing `debouncedId` without a `delay` value greater than 0 will throw an Error.
{% endhint %}

## Read more:

* 💡 [Add Job API Reference](https://api.docs.bullmq.io/classes/v5.Queue.html#add)

0 comments on commit d9f1c1d

Please sign in to comment.