diff --git a/docs/gitbook/SUMMARY.md b/docs/gitbook/SUMMARY.md index 012b930218..fa3416a74c 100644 --- a/docs/gitbook/SUMMARY.md +++ b/docs/gitbook/SUMMARY.md @@ -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) diff --git a/docs/gitbook/guide/jobs/debouncing.md b/docs/gitbook/guide/jobs/debouncing.md new file mode 100644 index 0000000000..f1bf496a4c --- /dev/null +++ b/docs/gitbook/guide/jobs/debouncing.md @@ -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)