最近我看到node-cron允许使用cron语法按计划执行功能。该模块像服务一样运行。
我创建了包含内容的文件test.js
var CronJob = require('cron').CronJob;
new CronJob('* * * * * *', function() {
console.log('You will see this message every second');
}, null, true, 'America/Los_Angeles');
此脚本一直运行,直到我按下 Ctrl + C
alok@alok-ThinkPad-T440p:/tmp$ node test.js
You will see this message every second
You will see this message every second
You will see this message every second
You will see this message every second
You will see this message every second
You will see this message every second
You will see this message every second
^C
alok@alok-ThinkPad-T440p:/tmp$
在python中,我发现python-crontab取决于系统级cron。我不想使用。我想使用类似于node-cron的东西。