Ad
Node Schedule Not Working With Object Variable?
I have programmed a schedule in node:
function setTimer(time){
t_SD1.on_h = time.on_h;
t_SD1.on_m = time.on_m;
t_SD1.off_h = time.off_h;
t_SD1.off_m = time.off_m;
console.log(t_SD1.on_h+' '+t_SD1.on_m);
}
var j = schedule.scheduleJob({hour: t_SD1.on_h, minute: t_SD1.on_m}, function(){
console.log('ONNNN');
console.log('0 '+t_SD1.on_m+' '+t_SD1.on_h+' * * *');
});
The time comes from:
var obj = JSON.parse(req.query.timer);
setTimer(obj);
Declaration:
var t_SD1 = {on_h: 14, on_m: 52, off_h: 14, off_m: 53};
Ok... now the problem:
When I start it without setTimer()
it works fine. The schedule triggers at 14:52. But when I start the setTimer()
function it does not work.
My console tells me the time 0 53 14 * * *
I have also tried it with parseInt(time.on_h)
, but the same result.
Ad
Answer
It's a bit hard to understand under which conditions it does and doesn't fail, but I think the problem stems from the fact that you call scheduleJob()
before setTimer()
. I think you need to adjust your first example to this:
function setTimer(time){
t_SD1.on_h = time.on_h;
t_SD1.on_m = time.on_m;
t_SD1.off_h = time.off_h;
t_SD1.off_m = time.off_m;
console.log(t_SD1.on_h+' '+t_SD1.on_m);
var j = schedule.scheduleJob({hour: t_SD1.on_h, minute: t_SD1.on_m}, function(){
console.log('ONNNN');
console.log('0 '+t_SD1.on_m+' '+t_SD1.on_h+' * * *');
});
}
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad