gpt4 book ai didi

javascript - Nodejs node-schedule npm 抛出错误 "this.job.execute is not a function"

转载 作者:行者123 更新时间:2023-11-29 21:31:24 26 4
gpt4 key购买 nike

我是 nodejs 的新手,我编写了一个 nodejs 程序并使用 node-schedule 每分钟安排一次。但是在运行了一段时间并在控制台生成了一些日志之后,nodejs 抛出了 this.job.execute is not a function

的错误

这是我使用的代码:

var nodeSchedule = require('node-schedule');

runJob();

function runJob(){
console.log("start");
nodeSchedule.scheduleJob('0 * * * * *',require('./prodModules.js'));

}

我得到的日志是:

C:\Users\1060641\Downloads\NodeJS HealthReport\Collector>node src\main\nodejs\collector_main.js
start
Connected
Ready
logged in as Super User
nfs_check running...
NFS Check completed
snapchart_check running...
C:\Users\1060641\node_modules\node-schedule\lib\schedule.js:177
this.job.execute();
^

TypeError: this.job.execute is not a function
at Job.invoke (C:\Users\1060641\node_modules\node-schedule\lib\schedule.js:177:14)
at null._onTimeout (C:\Users\1060641\node_modules\node-schedule\lib\schedule.js:445:11)
at Timer.listOnTimeout (timers.js:92:15)

C:\Users\1060641\Downloads\NodeJS HealthReport\Collector>

我认为我的 prodModules.js 没有任何问题,因为它可以独立运行,运行良好。调度正在抛出错误。

请帮忙。

最佳答案

Node 调度器回调必须是一个函数。将您的 runJob 更改为如下内容:

function runJob() {
console.log("start");
nodeSchedule.scheduleJob('0 * * * * *', function () {
require('./prodModules.js');
});
}

关于javascript - Nodejs node-schedule npm 抛出错误 "this.job.execute is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36336799/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com