Job Missing when application server restarts
- Dominant language
- JavaScript
- Stars
- 9.4k
- Forks
- 858
- PR merge metrics
- No merged PRs in 30d
Description
Hi
I ran the simple code to actually send email. in between i restarted my node server using pm2 restart. I noticed two things.
1. 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.
2. 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
}, 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.
});
});
module.exports = {
sendInvitationEmail: sendInvitationEmail
};
`
Contributor guide
No contributing guide indexed for this repository
Research direction
No repository file or test is named. Start by reproducing the restart scenario around jobs.process('send_invite_email'), job.save(), and the complete listener, using the provided PM2 restart sequence. Done should define and verify whether queued work survives a worker restart and how completion events behave afterward.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, redis
- Domain
- backend, distributed-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100