bull
bull copied to clipboard
The job returned by Queue.add() is not updated by progress()
Summary
The progress value of the Job returned by Queue.add() isn't updated. It's a surprising behavior considering that the Job objects returned by the events are.
Is it an intended behavior? If it is it should probably be added in the reference documentation
Reproduce / Test
When executing this program :
const Queue = require('bull')
let returnedJob = null
let activeJob = null
let queue = new Queue('test');
queue.process(async (_job, done) => {
await new Promise((resolve, reject) => {
let progress = 0
let i = setInterval(async () => {
progress += 1;
await _job.progress(progress)
if(progress == 100){
clearInterval(i)
resolve()
}
}, 100)
})
done()
})
queue.on('active', (job)=>{
activeJob = job
})
queue.on('progress', async (_job) => {
console.log('event_job : ' + await _job.progress())
console.log('active_job : ' + await activeJob.progress())
console.log('returned_job : ' + await returnedJob.progress())
})
queue.add({}).then((_job) => { returnedJob = _job})
We obtain the following traces :
...
event_job : 97
active_job : 97
returned_job : 0
event_job : 98
active_job : 98
returned_job : 0
event_job : 99
active_job : 99
returned_job : 0
event_job : 100
active_job : 100
returned_job : 0
Version
- node :
- v12.19.0
- v14.13.1
- bull : 3.18.1
I marked it as an enhancement.
I confirm this issue.
Although I agree it is an inconsistent behaviour there are several workarounds for this so it is not very high prioritized.
What are the workarounds? Retrieving the job by using Queue.getJob() before sending the progress event doesn't seem to work either.
@pascalprat you should not need any workarounds. The progress is reported as an event and that is they way it should be handled in your code. In a distributed system you cannot just rely on a particular instantiation of a job class to handle the progress reports. If you write your code listening to the events and reporting that to the user it would be the more robust and scalable way to do it.