Skip to content

Instantly share code, notes, and snippets.

@mattwynne
Created April 22, 2020 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattwynne/623cb45a4a63e7ad34fd57211dfe556e to your computer and use it in GitHub Desktop.
Save mattwynne/623cb45a4a63e7ad34fd57211dfe556e to your computer and use it in GitHub Desktop.
Puzzled about how whenCurrentJobsFinished is supposed to work
const Queue = require('bull')
const q = new Queue('test')
const main = async () => {
await q.clean(0, 'completed')
q.process(async job => {
console.log('work starting')
await new Promise(resolve => setTimeout(resolve, 3000))
console.log('work done')
})
q.on('completed', async job => {
console.log('on completed', await q.getJobCounts())
})
console.log('add job')
await q.add({})
console.log('wait', await q.getJobCounts())
const x = await q.whenCurrentJobsFinished()
console.log('waited', await q.getJobCounts())
await new Promise(resolve => setTimeout(resolve, 1000))
console.log('close', await q.getJobCounts())
await q.close()
console.log('closed')
}
main().catch(err => console.error(err))
add job
wait {
waiting: 1,
active: 0,
completed: 0,
failed: 0,
delayed: 0,
paused: 0
}
waited {
waiting: 1,
active: 0,
completed: 0,
failed: 0,
delayed: 0,
paused: 0
}
work starting
close {
waiting: 0,
active: 1,
completed: 0,
failed: 0,
delayed: 0,
paused: 0
}
work done
on completed {
waiting: 0,
active: 0,
completed: 1,
failed: 0,
delayed: 0,
paused: 0
}
closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment