OnQueueError not firing on task queue: NestJS + Bull

3.9k views Asked by At

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")
    }
}
1

There are 1 answers

1
Simon On BEST ANSWER

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