Reputation: 3038
In my node.js application i am implementing background job processing using bull module.
I need to catch certain events on the queue like completed
, failed
, error
.
I am trying to have a separate process for process function, but the problem is after moving the job processing to a process function i am unable to catch any of the event like completed
, failed
, error
.
Below is my code
processor.js
module.exports = async function(job, done) {
try {
await processExport.performExport(job.data.params, done);
} catch(err) {
console.log(err);
console.log('in error handling');
};
}
worker.js
const csvExportProcessing = require('../queue');
csvExportProcessing.process(5, __dirname + '/processor.js');
csvExportProcessing.on('completed', function(job, result){
console.log('job is now completed');
});
csvExportProcessing.on('failed', function(job, err){
if(job.attemptsMade == job.opts.attempts) {
//send a postback
}
});
csvExportProcessing.on('global:error', function(job, err){
console.log('Is last attempt? => ', (job.attemptsMade === job.opts.attempts));
});
Upvotes: 3
Views: 3001
Reputation: 3038
I was able to catch the events using the below code, here is the relevant code to catch failed
event
const myQueue = process.env.NODE_ENV == 'development' ? new Queue('myqueuename') : new Queue('myqueuename', 'redis://redis:6379/13');
setQueues([myQueue]);
myQueue.on('failed', async function(job, err){
if(job.attemptsMade == job.opts.attempts) {
//do something
}
});
Upvotes: 2