bull icon indicating copy to clipboard operation
bull copied to clipboard

The job returned by Queue.add() is not updated by progress()

Open oxabz opened this issue 5 years ago • 5 comments
trafficstars

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

oxabz avatar Nov 03 '20 20:11 oxabz

I marked it as an enhancement.

manast avatar Nov 04 '20 09:11 manast

I confirm this issue.

aalex avatar Apr 29 '21 17:04 aalex

Although I agree it is an inconsistent behaviour there are several workarounds for this so it is not very high prioritized.

manast avatar Apr 29 '21 18:04 manast

What are the workarounds? Retrieving the job by using Queue.getJob() before sending the progress event doesn't seem to work either.

pascalprat avatar Oct 15 '21 18:10 pascalprat

@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.

manast avatar Oct 16 '21 04:10 manast