Hi
I ran the simple code to actually send email. in between i restarted my node server using pm2 restart. I noticed two things.
when it restarted one job went missing (is this normal). See code below I had 10 jobs to send email. But only 9 emails were send. Is there a way to prevent it.
After restart complete event never got fired even though emails were send.
0|| Message sent: undefined
0|| Job 46 with name Send Invitation Email is done
0|| Message sent: undefined
0|| Job 47 with name Send Invitation Email is done
0|| Message sent: undefined
0|| Job 48 with name Send Invitation Email is done
0|| info: Server started at port 4000
0|| Message sent: undefined
0|| Message sent: undefined
0|| Message sent: undefined
0|| Message sent: undefined
0|| Message sent: undefined
0|| Message sent: undefined`
var sendInvitationEmail = function (data, user) {
//name = name || 'Default_Name';
var job = jobs.create('send_invite_email', {
name: 'Send Invitation Email',
invitation: data,
username: user.name,
email: user.email
});
job
.on('complete', function () {
console.log('Job', job.id, 'with name', job.data.name, 'is done');
})
.on('failed', function () {
console.log('Job', job.id, 'with name', job.data.name, 'has failed');
});
job.save();
}
jobs.process('send_invite_email', function (job, done) {
/ carry out all the job function here /
smtpTransport.sendMail({ //email options
from: "xxxxxxxxxx", // sender address. Must be the same as authenticated user if using Gmail.
to: "xxxxxx@gmail.com", // receiver
subject: "xxxx ", // subject
text: "Text comes here. Title --- " + job.data.invitation.name // body
}, function (error, response) { //callback
if (error) {
console.log(error);
done && done();
} else {
console.log("Message sent: " + response.message);
done && done();
}
smtpTransport.close(); // shut down the connection pool, no more messages. Comment this line out to continue sending emails.
});
Hi I ran the simple code to actually send email. in between i restarted my node server using pm2 restart. I noticed two things.
when it restarted one job went missing (is this normal). See code below I had 10 jobs to send email. But only 9 emails were send. Is there a way to prevent it.
After restart complete event never got fired even though emails were send.
0|| Message sent: undefined 0|| Job 46 with name Send Invitation Email is done 0|| Message sent: undefined 0|| Job 47 with name Send Invitation Email is done 0|| Message sent: undefined 0|| Job 48 with name Send Invitation Email is done 0|| info: Server started at port 4000 0|| Message sent: undefined 0|| Message sent: undefined 0|| Message sent: undefined 0|| Message sent: undefined 0|| Message sent: undefined 0|| Message sent: undefined`
my full code is below
`var kue = require('kue'), jobs = kue.createQueue(), nodemailer = require('nodemailer'), smtpTransport = require('nodemailer-smtp-transport');
var smtpTransport = nodemailer.createTransport(smtpTransport({ service: 'gmail', // host:'smtp.gmail.com', // port:465, // secure:true, auth: { user: "email", pass: "pass" } }));
var sendInvitationEmail = function (data, user) { //name = name || 'Default_Name'; var job = jobs.create('send_invite_email', { name: 'Send Invitation Email', invitation: data, username: user.name, email: user.email }); job .on('complete', function () { console.log('Job', job.id, 'with name', job.data.name, 'is done'); }) .on('failed', function () { console.log('Job', job.id, 'with name', job.data.name, 'has failed'); }); job.save(); }
jobs.process('send_invite_email', function (job, done) { / carry out all the job function here / smtpTransport.sendMail({ //email options from: "xxxxxxxxxx", // sender address. Must be the same as authenticated user if using Gmail. to: "xxxxxx@gmail.com", // receiver subject: "xxxx ", // subject text: "Text comes here. Title --- " + job.data.invitation.name // body
});
module.exports = { sendInvitationEmail: sendInvitationEmail }; `