Skip to content

Run BullMQ workers $onReady? #2764

Open
@denis-maiorov-brightsec

Description

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

Activity

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

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions