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

Controls for nestjs/bullmq processors in request-scoped providers #2030

Closed
1 task done
idbenami opened this issue Mar 11, 2024 · 4 comments
Closed
1 task done

Controls for nestjs/bullmq processors in request-scoped providers #2030

idbenami opened this issue Mar 11, 2024 · 4 comments
Labels

Comments

@idbenami
Copy link

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

I've recently integrated bullmq to my nestjs application using the @nestjs/bullmq module and I have a small problem.
My application is a multi-tenant application, and the app is loading the tenants dynamically when the application starts (inside OnModuleInit), the app also using Kafka and we've developed a custom module for multi-tenant communication thought Kafka, and there's another OnApplicationBootstrap function.

As soon as the BullExplorer OnModuleInit is finished the processors are taking jobs from the queue and I'm missing controls to tell the processors when they can start taking jobs, since I need those logics to finish first.

I tried to resolve the processors (app.resolve) after the app has started and call XXXprocessor.worker.pause() but I'm getting an error that I can't interact with the worker.

Describe the solution you'd like

I want to decide when my application starts processing jobs from the queue

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

because my app is loading the tenants data dynamically, the app isn't ready for processing jobs right away

@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@idbenami
Copy link
Author

@kamilmysliwiec I'm wondering how it's best to implement this.
bullmq worker can accept autorun: false, but then somehow I need to tell the worker to start running.
I'm not sure how to implement this for all processors and event-listeners, like a high-level autorun.

What do you think about exposing an option in QueueOptions for not running any logic in BullExplorer.onModuleInit and then exposing the registration logic ( this.registerWorkers(); this.registerQueueEventListeners(); ) to the developer to run?
I know it's a naive solution but it's simple to implement and gives the developer a simple way to tell all processors and event-listeners to run.

@kamilmysliwiec
Copy link
Member

I think that's OK. Then we could expose a manual flag that turns off the auto-registration

@kamilmysliwiec
Copy link
Member

Let's track this here #2038

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

2 participants