Michael Mitch
Michael Mitch

Reputation: 433

Cannot read property 'cancel' of undefined - node-schedule

nodejs tells me Cannot read property 'cancel' of undefined when i want to exectue job.cancel()

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


test = schedule.scheduleJob({second: 2, hour: 
dataA[0].on_h , minute: dataA[0].on_m, dayOfWeek: 
timerSD.day}, function(){ 
    console.log(now+': Timer automatic ON  - SD: '+x+ "timer ID"+dataA[0].ID);
    db.setStatus(x, 1);
});
test.cancel();

Upvotes: 0

Views: 591

Answers (1)

Michael Mitch
Michael Mitch

Reputation: 433

I do a workaround with reschedule. This works:

test = schedule.scheduleJob({second: 3, hour: dataA[0].off_h , minute: dataA[0].off_m, dayOfWeek: timerSD.day}, function() {
                console.log(now+': Timer automatic OFF - SD: '+x+ "timer ID."+dataA[0].ID);
                db.setStatus(x, 0);
            });
test.reschedule(true);

Upvotes: 0

Related Questions