Heroku自定义时钟进程无法使用cron在每个时间间隔运行

时间:2016-12-16 06:04:53

标签: node.js heroku cron

我不确定我做错了什么,但我试图关注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

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

我追随的文章是否旧版本不再适用?我应该如何正确地给工人打电话?

1 个答案:

答案 0 :(得分:0)

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

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