我在 NodeJS 中有一个电子邮件数据库服务器,它在以下时间范围内发送预定的电子邮件。
Email 1: Immediately
Email 2: 3 days after email 1
Email 3: 7 days after email 1
但是,当向应用程序提交多个条目时,它会抛出调度,以随机方式逐步执行 setTimeouts。
这是安排电子邮件的相关代码
server.post('/api/addUser', (req, res) => {
MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("heroku_XXXXXXXX");
var myobj = { recruiter: req.body.recruiter, firstName: req.body.firstName, lastName: req.body.lastName, profile: req.body.profile, email: req.body.email, emailStep: 'Step 1', emailsCancelled: 'No', source: req.body.source, company: req.body.company, role: req.body.role };
dbo.collection("users").insertOne(myobj, function(err, data) {
if (err) throw err;
res.status(200).send('success');
db.close();
sendMail(myobj,req.body.emailOne, "Step 1");
var sched = later.parse.recur().every(72).hour(),
t = later.setTimeout(function() { sendMail(myobj,req.body.emailTwo, "Step 2"); }, sched);
var sched2 = later.parse.recur().every(168).hour(),
u = later.setTimeout(function() { sendMail(myobj,req.body.emailThree, "Step 3"); }, sched2);
});
});
});
电子邮件很好,它们正在传递给 SendGrid 好的,只是日程安排出了问题。我试过删除 LaterJS 并只使用 setTimeouts 但这也没有奏效。