This package has been moved to @nestjs/bull. It won't be maintained here anymore, consider updating your dependencies accordingly. (https://www.npmjs.com/package/@nestjs/bull)
This module provides some decorators that will help you to set up your queue listeners.
@Processor()
The @Processor() class decorator is mandatory if you plan to use this package's decorators.
It accepts an optional QueueDecoratorOptions argument:
exportinterfaceQueueDecoratorOptions{
name?:string;// Name of the queue
}
@Process()
The @Process() method decorator flags a method as a processing function for the queued jobs.
It accepts an optional QueueProcessDecoratorOptions argument:
exportinterfaceQueueProcessDecoratorOptions{
name?:string;// Name of the job
concurrency?:number;// Concurrency of the job
}
Whenever a job matching the configured name (if any) is queued, it will be processed by the decorated method.
Such method is expected to have the following signature (job: Job, done?: DoneCallback): any;
@OnQueueEvent()
The OnQueueEvent() method decorator flags a method as an event listener for the related queue.
It requires a BullQueueEvent argument:
exporttypeBullQueueEvent=
|'error'
|'waiting'
|'active'
|'stalled'
|'progress'
|'completed'
|'failed'
|'paused'
|'resumed'
|'cleaned'
|'drained'
|'removed'
|'global:error'
|'global:waiting'
|'global:active'
|'global:stalled'
|'global:progress'
|'global:completed'
|'global:failed'
|'global:paused'
|'global:resumed'
|'global:cleaned'
|'global:drained'
|'global:removed';
You can also use the BullQueueEvents and BullQueueGlobalEvents enums.
Fortunately, there is a shorthand decorator for each of the Bull events:
@OnQueueError()
@OnQueueWaiting()
@OnQueueActive()
@OnQueueStalled()
@OnQueueProgress()
@OnQueueCompleted()
@OnQueueFailed()
@OnQueuePaused()
@OnQueueResumed()
@OnQueueCleaned()
@OnQueueDrained()
@OnQueueRemoved()
@OnGlobalQueueError()
@OnGlobalQueueWaiting()
@OnGlobalQueueActive()
@OnGlobalQueueStalled()
@OnGlobalQueueProgress()
@OnGlobalQueueCompleted()
@OnGlobalQueueFailed()
@OnGlobalQueuePaused()
@OnGlobalQueueResumed()
@OnGlobalQueueCleaned()
@OnGlobalQueueDrained()
@OnGlobalQueueRemoved()
If you need more details about those events, head straight to Bull's reference doc.
Example
Here is a pretty self-explanatory example on how this package's decorators should be used.
`Processing job ${job.id} of type ${job.name} with data ${job.data}...`,
);
}
@OnQueueEvent(BullQueueEvents.COMPLETED)
onCompleted(job:Job){
this.logger.log(
`Completed job ${job.id} of type ${job.name} with result ${job.returnvalue}`,
);
}
}
Separate processes
This module allows you to run your job handlers in fork processes.
To do so, add the filesystem path to a file (or more) exporting your processor function to the processors property of the BullModule options.
You can read more on this subject in Bull's documentation.
Please note that, your function being executed in a fork, Nestjs' DI won't be available.