Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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

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. Scheduling is throwing errors.

Please help.

like image 315
aiman Avatar asked Mar 31 '16 14:03

aiman


1 Answers

The node-scheduler callback must be a function. Change your runJob to something like this:

function runJob() {
    console.log("start");
    nodeSchedule.scheduleJob('0 * * * * *', function () { 
        require('./prodModules.js');
    });
}
like image 113
gmanolache Avatar answered Oct 06 '22 00:10

gmanolache