Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
oxabz opened this issue Nov 3, 2020 · 5 comments
Open

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

oxabz opened this issue Nov 3, 2020 · 5 comments

Comments

@oxabz
Copy link

oxabz commented Nov 3, 2020

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
@manast
Copy link
Member

manast commented Nov 4, 2020

I marked it as an enhancement.

@aalex
Copy link

aalex commented Apr 29, 2021

I confirm this issue.

@manast
Copy link
Member

manast commented Apr 29, 2021

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

@pascalprat
Copy link

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

@manast
Copy link
Member

manast commented Oct 16, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants