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.
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');
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With