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

Question: Is there a way to get the jobs position in the queue? #1388

Closed
ryankauk opened this issue Jul 16, 2019 · 2 comments
Closed

Question: Is there a way to get the jobs position in the queue? #1388

ryankauk opened this issue Jul 16, 2019 · 2 comments
Labels

Comments

@ryankauk
Copy link

Hey there, just started using your package, everything seems perfect so far, except I'm looking for a way to get the position in the queue by job id. Is there a functionality for it or maybe some direction how to do this?

@stansv
Copy link
Contributor

stansv commented Jul 16, 2019

I don't think the optimal solution exists, anyway linear search is required. With Bull you can simply do:

    const waiting = await queue.getWaiting();

    for (let i = 0; i < waiting.length; i++) {
        const job = waiting[i];
        if(job.id === someId) return i; // 0 means job is 1st in queue
    }

Job priorities are also taken into account.

Faster solution will include lua scripting as described here https://stackoverflow.com/a/8925470. There is bull:queueName:wait key holding all queued jobs in value of type LIST, you can adapt script for this case and use ioredis to execute it.

@stale
Copy link

stale bot commented Jul 12, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 12, 2021
@manast manast closed this as completed Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants