From 83c8e281f7c30caf82fa9c3e21775a507b560378 Mon Sep 17 00:00:00 2001 From: David Walsh <5778036+rhinodavid@users.noreply.github.com> Date: Fri, 31 Jan 2020 00:50:30 -0700 Subject: [PATCH] docs: fix QueueEvents examples in quick start guide --- docs/gitbook/README.md | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/docs/gitbook/README.md b/docs/gitbook/README.md index 23b703dd81..4b5173479b 100644 --- a/docs/gitbook/README.md +++ b/docs/gitbook/README.md @@ -74,16 +74,36 @@ import { QueueEvents } from 'bullmq' const queueEvents = new QueueEvents(); -queueEvents.on('completed', (jobId) => { - console.log(`${jobId} has completed!`); +queueEvents.on('waiting', ({ jobId }) => { + console.log(`A job with ID ${jobId} is waiting`); }); -queueEvents.on('failed', (jobId, err) => { - console.log(`${jobId} has failed with ${err.message}`); +queueEvents.on('active', ({ jobId, prev }) => { + console.log(`Job ${jobId} is now active; previous status was ${prev}`); +}); + +queueEvents.on('completed', ({ jobId, returnvalue }) => { + console.log(`${jobId} has completed and returned ${returnvalue}`); +}); + +queueEvents.on('failed', ({ jobId, failedReason }) => { + console.log(`${jobId} has failed with reason ${failedReason}`); +}); +``` + +You may also access the timestamp of the event, which looks like "1580456039332-0". + +```typescript +import { QueueEvents } from 'bullmq' + +const queueEvents = new QueueEvents(); + +queueEvents.on('progress', ({ jobId, data }, timestamp) => { + console.log(`${jobId} reported progress ${data} at ${timestamp}`); }); ``` {% hint style="danger" %} -Note that the global events listeners do only return the job Id, not the job instance. This is for performance reasons, if you need the complete job you can always use the`Queue##getJob method.` +For performance reasons the events emited by a `QueueEvents` instance do not contain the `Job` instance, only the `jobId`. Use the `Queue##getJob` method if you need the `Job` instance. {% endhint %}