节点服务器重新启动后运行Cron作业(挥发性,可恢复性,持久性) [英] Run Cron Jobs after the Node server restarts (volatility, recoverability, durability)
问题描述
我使用了NPM中的 cron 库。
我想为用户创建事件,创建预期在事件发生后一个月内执行的作业。
让我们说这是我的代码:
function userSignedUpEvent(user){
var today = new Date();
today.setDate(today.getDate()+ 30);
let cronSignature =`$ {today.getMinutes()} $ {today.getHours()} $ {today.getDate()} $ {today.getMonth()} *`
let reminderJob = new CronJob(cronSignature,
()=> {
user.sendEmail(已经加入我们一个月了!);
},null,true, 亚洲/耶路撒冷);
}
问题是如果服务器在确切的时间关闭cron-signature,代码永远不会被执行。
我的情况下有没有办法保存这些作业,并在服务器重新启动时再次签名? / p>
理论上,我可以将自己的签名保存在我的数据库中,并由我自己实现,但是我想确保没有一个驱动的方法来实现。 >
所以我在这个项目中实现了这个:
crone-durable
I use the cron library in NPM.
I want to make events for users, that create jobs that are expected to be executed in a month after the event.
Let's say that this is my code:
function userSignedUpEvent(user) {
var today = new Date();
today.setDate(today.getDate() + 30);
let cronSignature = `${today.getMinutes()} ${today.getHours()} ${today.getDate()} ${today.getMonth()} *`
let reminderJob = new CronJob(cronSignature,
() => {
user.sendEmail("It has been a month since you joined us!");
}, null, true, "Asia/Jerusalem");
}
The problem is that if the server is shut-down at the exact time of the cron-signature, the code will never be executed.
Is there a way in my case to save these jobs and sign them again whenever the server is up again?
Theoretically, I can save their signatures in my Database and implement that by myself, but I want to be sure there isn't a driven method to do it.
So I've implemented this in this project: crone-durability
这篇关于节点服务器重新启动后运行Cron作业(挥发性,可恢复性,持久性)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!