简体   繁体   English

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

[英]Nodejs node-schedule npm is throwing error "this.job.execute is not a function"

I'm new to nodejs and I have written a nodejs program and scheduling it every minute using the node-schedule.我是 nodejs 的新手,我编写了一个 nodejs 程序并使用 node-schedule 每分钟调度一次。 but after running for some time and generating a couple of logs at the console, nodejs throws error that this.job.execute is not a function但是在运行了一段时间并在控制台生成了几个日志后,nodejs 抛出了this.job.execute is not a function错误

here is the code I am using:这是我正在使用的代码:

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

runJob();

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

}

the logs I am getting is:我得到的日志是:

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>

I don't think there is anything wrong with my prodModules.js since running it standalone its running fine.我不认为我的prodModules.js有什么问题,因为它是独立运行的,它运行良好。 Scheduling is throwing errors.调度正在抛出错误。

Please help.请帮忙。

The node-scheduler callback must be a function.节点调度器回调必须是一个函数。 Change your runJob to something like this:将您的 runJob 更改为如下所示:

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

Try re-importing 'node-schedule', I ran your code with a fresh import, and it works as expected.尝试重新导入“node-schedule”,我使用全新导入运行了您的代码,并且它按预期工作。

To down import on windows cmd : > npm install node-schedule要在 Windows cmd 上向下导入:> npm install node-schedule

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM