在节点中调用Cronjob的API没有任何响应



我试图从cronjob中调用slackbot api从cronjob中召集。以下是相关代码:

Shiftbot.prototype.run = function () {
    Shiftbot.super_.call(this, this.settings);
    this.on('start', this._onStart);
    this.on('message', this._onMessage);
};
Shiftbot.prototype._onStart = function() {
    this._loadBotUser();
    new CronJob('* * 16 * * *', function(){
        console.log('You will see this message every second ');
        Shiftbot.prototype._sendReminder();
    }, null, true, "America/New_York");
}
Shiftbot.prototype._sendReminder = function() { 
    console.log('test');
    this.postMessageToChannel("shiftbot_beta", "Cron test", {as_user: true});
}

上面的_sendReminder方法从另一个Shiftbot.prototype.*方法调用,而不是从cronjob内进行调用时可以正常工作。任何帮助将不胜感激!

在shiftbot.protype的范围中创建了变量self,并在CronJob的范围内使用了它:

Shiftbot.prototype._onStart = function() {
    var self = this;
    this._loadBotUser();
    new CronJob('* * 16 * * *', function(){
        console.log('You will see this message every second ');
        self._sendReminder();
    }, null, true, "America/New_York");
}

最新更新