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));
});