我想每天调用一个函数(24小时),从当前时间开始,但它只运行7天,而不是更多!我正在使用Nestjs (@nestjs/调度程序)
@Cron(new Date(Date.now() + (24*60*60*1000) * 7)
function() {
console.log("This should get called each day during the next 7 days")
}我试着读文档,但是我想不出怎么做这样的事情
发布于 2021-12-24 15:22:02
startTime = new Date().getTime();
@Cron(`* * 0-23/24 * * *`, {
name: 'myJob',
})
handleCron() {
console.log(`Called every day for the next 7 days`);
this.closeJob();
}
closeJob() {
const job = this.schedulerRegistry.getCronJob('myJob');
const endTime = this.startTime + 1000 * 60 * 60 * 24 * 7;
if (job.lastDate().getTime() > endTime) {
job.stop();
}
}https://stackoverflow.com/questions/70460707
复制相似问题