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

Run BullMQ workers $onReady? #2764

Open
denis-maiorov-brightsec opened this issue Jul 25, 2024 · 1 comment
Open

Run BullMQ workers $onReady? #2764

denis-maiorov-brightsec opened this issue Jul 25, 2024 · 1 comment
Assignees

Comments

@denis-maiorov-brightsec

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

Default configuration of BullMQ workers uses autorun: true and as a result the worker runs before async providers are built that establish db connections, etc.
So, any waiting to be executed job fails during startup as the server is not yet properly initialized
https://docs.bullmq.io/guide/workers

Describe the solution you'd like

Not sure what is the best practices there but I feel that framework should handle this. Http server is not listening before all the routes, hooks and providers are built so the same behavior should be regarding processing jobs from queues

Describe alternatives you've considered

Solution today is to disable autorun through defaultWorkerOptions
Manually inject workers

@Inject(BullMQTypes.WORKER) private readonly workers: Worker[]

and then do in $afterInit hook

// do not await run as it never resolves
this.workers.forEach(worker => worker.run());

Additional context

No response

Acceptance criteria

No response

@Romakita
Copy link
Collaborator

Hello @denis-maiorov-brightsec
Maybe delay job startup at the approriate hook will be the solution as you suggested ;)

Let's go for a small pr !

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

2 participants