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

How to get jobs from getNextJob() continuously? #679

Closed
StanleyAM opened this issue Aug 9, 2021 · 3 comments
Closed

How to get jobs from getNextJob() continuously? #679

StanleyAM opened this issue Aug 9, 2021 · 3 comments

Comments

@StanleyAM
Copy link

How to get jobs from getNextJob() continuously when there have multiple jobs at the waiting state in the queue?

Below is the sample code:

const worker = new Worker('foo', null, { connection });
const token = 'the-token';

setInterval(async () => {
    const job = (await worker.getNextJob(token)) as Job;
    if (job) {
        console.log(job.data);
        await job.moveToCompleted('the result', token);
    }
}, 1000);

But there is always getting only one job in the loop. What is the proper way to get jobs from getNextJob() continuously?

Thanks!

@manast
Copy link
Contributor

manast commented Aug 9, 2021

Let me know if this piece of documentation is of any help:
https://docs.bullmq.io/patterns/manually-fetching-jobs#looping-through-jobs

@StanleyAM
Copy link
Author

Oh! I omit there is also returning the next job in the waiting queue at the API "moveToCompleted".
Thank you @manast !

@manast
Copy link
Contributor

manast commented Aug 10, 2021

@StanleyAM yes that is an optimization to save one roundtrip per job, you can disable this behaviour passing false as the third argument of moveToCompleted.

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

No branches or pull requests

2 participants