我有以下在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);
}
});
};发布于 2017-03-11 22:29:14
我在文档中找到这个:Processing Concurrency Processing Concurrency
默认情况下,对queue.process()的调用一次只接受一个作业进行处理。对于发送电子邮件这样的小任务,这并不理想,因此我们可以通过传递一个数字来指定此类型的最大活动作业数:
queue.process('email', 20, function(job, done){
// ...
});https://stackoverflow.com/questions/42736278
复制相似问题