In BullMQ, you can check the status of a job by using its getState
method. This will return the current state of the job in the queue.
const Queue = require('bullmq').Queue; const queue = new Queue('my-queue'); async function getJobStatus(jobId) { const job = await queue.getJob(jobId); if (job === null) { console.log('No job found with id ' + jobId); } else { const state = await job.getState(); console.log('Job state is: ' + state); } } getJobStatus('some-job-id');
In this example, getJobStatus
function takes a jobId
as an argument and retrieves the job from the queue. If the job exists, it gets the job's state using getState()
. The potential states of a job in BullMQ are: completed
, failed
, delayed
, active
, waiting
, paused
, or stuck
.
Please note that getJobStatus
is an asynchronous operation because it needs to communicate with the Redis server where your jobs are stored. Therefore, it should be used inside an async function or handled with promise-based syntax.
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.