Kue无法正常工作



我有以下在kue

发送邮件的代码
require('dotenv').load();
const mailer = require('../helper/mailer');
const kue = require('kue'),
  queue   = kue.createQueue();
console.log("Starting server");
queue.process('email',function(job,done){
  console.log(job.data);
  mailer
    .prepareContext(job.data)
    .then(mailer.prepareBody)
    .then(mailer.prepareMail)
    .then(mailer.sendMail)
    .then((data)=>{
      console.log("Mail sent");
    })
    .catch((err)=>{
      console.log(err.message);
    });
});
queue.on('error',(err)=>{
  console.log(err);
});

问题是它仅在第一个事件中做出响应。我必须重新启动脚本以发送另一个。我在这里做错了吗?

我正在使用

添加事件
helper.sendVerificationMail = function(data){
  return new Promise(function(fullfill,reject){
    try{
      var ctx = {};
      ctx.from = "account";
      ctx.to_email = data.email;
      ctx.subject = "Verifiy your email address";
      ctx.template = "signup";
      ctx.ctx = {};
      ctx.ctx.verification = data.verification;
      queue.create('email',ctx).save();
      fullfill(data);
    }catch(err){
      reject(err);
    }
  });
};

我在文档上找到了这一点:处理并发处理并发

默认情况下,呼叫queue.process()一次只能接受一项工作。对于诸如发送电子邮件之类的小任务,这不是理想的选择,因此我们可以通过一个数字来指定此类型的最大活动作业:

queue.process('email', 20, function(job, done){
  // ...
});

最新更新