【发布时间】:2020-01-01 21:43:07
【问题描述】:
我正在尝试使用 pm2 在午夜运行 cron。
使用此设置,我面临一个意外情况,即一旦我启动该进程,就会触发一次 cron。
有没有一种方法可以在无需验证 cron 进程中的运行时间的情况下进行配置?
生态系统.config.js
module.exports = {
apps: [
{
name: "server",
script: "server.js",
watch: false,
env: {
NODE_ENV: "production"
}
},
{
name: "test-cron",
script: "test-cron.js",
instances: 1,
exec_mode: "fork",
cron_restart: "0 0 * * *",
watch: false,
autorestart: false,
env: {
NODE_ENV: "production"
}
}
]
};
命令
pm2-runtime ecosystem.config.js
test-cron.js
console.log("CRON EXECUTED");
控制台输出:
> pm2-test@1.0.0 start /Users/sudhirshrestha/workspace/pm2-test
> pm2-runtime ecosystem.config.js
2019-08-28T22:54:44: PM2 log: Launching in no daemon mode
2019-08-28T22:54:44: PM2 log: App [server:0] starting in -fork mode-
2019-08-28T22:54:44: PM2 log: App [test-cron:1] starting in -fork mode-
2019-08-28T22:54:44: PM2 log: App [server:0] online
2019-08-28T22:54:44: PM2 log: App [test-cron:1] online
CRON EXECUTED
2019-08-28T22:54:49: PM2 log: App [test-cron:1] exited with code [0] via signal [SIGINT]
问题:Cron 在启动时立即自动运行一次
【问题讨论】:
标签: javascript node.js cron pm2