Skip to content

Commit

Permalink
Merge pull request #123 from rhinodavid/queue_events_doc
Browse files Browse the repository at this point in the history
docs: fix QueueEvents examples in quick start guide
  • Loading branch information
manast authored Feb 1, 2020
2 parents 9d796a1 + 83c8e28 commit 195e877
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions docs/gitbook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

0 comments on commit 195e877

Please sign in to comment.