'OnQueueError not firing on task queue: NestJS + Bull
I've noticed that bull does not print exceptions to the console by default. To get around this I want to catch errors with the @OnQuerueError
decorator and print them to the console (for now). My current implementation does not work and I don't understand why. The handler
is not called. I verified that other event listeners work such as @OnQueueActive()
:
@Processor('email')
export default class DigestEmailProcessor {
constructor(
) {}
@OnQueueError()
handler() {
console.log('fired exception');
}
@Process(PROCESS_NAMES.email.send)
async send(job: Job<JobData>) {
throw new Error("Foo bar")
}
}
Solution 1:[1]
The event listener @OnQueueError()
is not correct for this use case.
Try using the event listener @OnQueueFailed()
this raises an event for jobs that have thrown an error.
using your example code:
@Processor('email')
export default class DigestEmailProcessor {
constructor(
) {}
@OnQueueFailed()
handler(job: Job, error: Error) {
console.log('fired exception');
}
@Process(PROCESS_NAMES.email.send)
async send(job: Job<JobData>) {
throw new Error("Foo bar")
}
}
more information on the different event listeners
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Simon |