简体   繁体   English

Bull 用于作业处理的单独进程无法捕获队列中的事件

[英]Bull separate process for job processing unable to catch events on queue

In my node.js application i am implementing background job processing using bull module.在我的 node.js 应用程序中,我正在使用公牛模块实现后台作业处理。 I need to catch certain events on the queue like completed , failed , error .我需要捕获队列中的某些事件,例如completedfailederror

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 .我正在尝试为进程 function 设置一个单独的进程,但问题是在将作业处理移动到进程 function 之后,我无法捕捉到任何事件,例如completedfailederror

Below is my code下面是我的代码

processor.js处理器.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 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));
});

I was able to catch the events using the below code, here is the relevant code to catch failed event我能够使用以下代码捕获事件,这是捕获failed事件的相关代码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM