0

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();
Michael Mitch
  • 403
  • 2
  • 7
  • 17
  • Possible duplicate of [Cancel node-schedule event after it has been set](https://stackoverflow.com/questions/33113287/cancel-node-schedule-event-after-it-has-been-set) – eol Apr 28 '19 at 15:21

1 Answers1

0

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);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Michael Mitch
  • 403
  • 2
  • 7
  • 17