我有以下代码用于发送邮件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);
}
});
};