Reputation: 169
I have a BullMQ dynamic queue. Is there a way to check how many items there in queue? I already checked in google & stackoverflow and cannot find any solution.
Upvotes: 1
Views: 2310
Reputation: 31
You can use the getters
documentation from BullMQ. It can be found here.
const counts = await myQueue.getJobCounts('wait', 'completed', 'failed')
Or, to have all statuses returned:
const counts = await myQueue.getJobCounts()
Note that the myQueue
variable must be available to be called. It is the instantiated queue you've created previously:
const myQueue = new Queue('queue-name', options)
getJobCounts()
will return the following object:
{
"active": 1,
"completed": 4555,
"delayed": 0,
"failed": 0,
"paused": 0,
"prioritized": 0,
"waiting": 0,
"waiting-children": 0
}
The items in the waiting
status are the ones not picked up yet by any worker.
Upvotes: 0
Reputation: 851
I suspect there is a better way of doing it, but something like this may work for you:
Queue#getJobs(['waiting', 'active', 'completed', 'failed', 'delayed', 'paused'], 0, 0, false) // meaning asc: false = descending
And check the id for each type of job from the results, sort those descending, and grab the first result.
If you found a better way, please post it.
Upvotes: 0