【问题标题】:Heroku custom clock process fails to run at each interval using cronHeroku 自定义时钟进程无法使用 cron 在每个时间间隔运行
【发布时间】:2017-05-01 21:12:42
【问题描述】:

我不确定我做错了什么,但我正在尝试关注this 文章。我有以下 Procfile:

web: node index.js
worker: node bot.js
clock: node clock.js

在我的clock.js中,我有:

var CronJob = require('cron').CronJob;
var bot = require('./bot.js');

new CronJob({
    cronTime: "* * * * *",
    onTick: bot.start(),
    start: true,
    timeZone: "America/Los_Angeles"
});

我的 bot.js 的结构如下:

var config = require('./config');
// ... other includes

module.exports = {
    start: function() {
        // code
    }
}

我的结构与文章几乎完全一致,但发生了什么?这是我的日志:

2016-12-16T06:00:48.935847+00:00 heroku[web.1]: Starting process with command `node index.js`
2016-12-16T06:00:49.332925+00:00 heroku[worker.1]: Starting process with command `node bot.js`
2016-12-16T06:00:49.736519+00:00 heroku[clock.1]: Starting process with command `node clock.js`
2016-12-16T06:00:50.058125+00:00 heroku[worker.1]: State changed from starting to up
2016-12-16T06:00:50.395082+00:00 heroku[clock.1]: State changed from starting to up
2016-12-16T06:00:51.899971+00:00 app[web.1]: app running on port 21470
2016-12-16T06:00:52.505353+00:00 heroku[worker.1]: State changed from up to crashed
2016-12-16T06:00:52.491705+00:00 heroku[worker.1]: Process exited with status 0
2016-12-16T06:00:52.698864+00:00 heroku[web.1]: State changed from starting to up

所以我可以看到我正在启动工人(它什么都不做)然后它崩溃了。然后我的时钟启动了,但再也没有给工人打电话?它绝对不是每分钟都启动。

我关注的文章是否陈旧且不再适用?如何正确称呼工人?

【问题讨论】:

    标签: node.js heroku cron


    【解决方案1】:

    你在 bot.start() 的某处有 process.exit(0) 命令吗?

    Heroku 在遇到命令时会导致 dyno 崩溃(有关更多信息,请参阅 this link)。如果您删除它,它应该可以解决问题。发布完整的 bot.start 函数以进行验证会很有帮助。

    【讨论】:

      猜你喜欢
      • 2021-08-14
      • 2012-08-08
      • 2023-02-15
      • 1970-01-01
      • 2015-02-24
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      • 2020-07-01
      相关资源
      最近更新 更多