Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix QueueEvents examples in quick start guide #123

Merged
merged 1 commit into from
Feb 1, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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".
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anybody know what the suffix (-0) is? Does it increment when multiple events get fired during the same ms?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


```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 %}