Created
April 22, 2020 17:26
-
-
Save mattwynne/623cb45a4a63e7ad34fd57211dfe556e to your computer and use it in GitHub Desktop.
Puzzled about how whenCurrentJobsFinished is supposed to work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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