Quick Start
This is a basic guide to get your first queue working.
Last updated
Was this helpful?
Was this helpful?
import { Worker } from 'bullmq';
import IORedis from 'ioredis';
const connection = new IORedis({ maxRetriesPerRequest: null });
const worker = new Worker(
'foo',
async job => {
// Will print { foo: 'bar'} for the first job
// and { qux: 'baz' } for the second.
console.log(job.data);
},
{ connection },
);worker.on('completed', job => {
console.log(`${job.id} has completed!`);
});
worker.on('failed', (job, err) => {
console.log(`${job.id} has failed with ${err.message}`);
});import { QueueEvents } from 'bullmq';
const queueEvents = new QueueEvents("my-queue-name");
queueEvents.on('waiting', ({ jobId }) => {
console.log(`A job with ID ${jobId} is waiting`);
});
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}`);
});import { QueueEvents } from 'bullmq';
const queueEvents = new QueueEvents("my-queue-name");
queueEvents.on('progress', ({ jobId, data }, timestamp) => {
console.log(`${jobId} reported progress ${data} at ${timestamp}`);
});