javascript - onComplete() does not get called in node cron -
hi trying test out node-cron not able desired response in 1 case.
i need initiate cron request 1 more time when current cron gets completed. so, need oncomplete() called not able callback.
my code snippet :
cronwrapper.prototype.pushnotificationcron = function() {     // change console winston in real implementation.     console.log('creating job');     var jobpattern = '*/10 * * * * *';     var job = new cronjob(jobpattern, onjobstarted, onjobcompleted, false);     console.log('starting job');     job.start(); };  var onjobstarted = function(){     var date = new date();     console.log('cron started on \t' + date);     return; };  var onjobcompleted = function(){     winston.info('job completed:'); }; output:
cron started on     tue dec 16 2014 12:59:40 gmt+0530 (ist) cron started on     tue dec 16 2014 12:59:50 gmt+0530 (ist) cron started on     tue dec 16 2014 13:00:00 gmt+0530 (ist) please point out mistake making.
lib details:
"cron":"1.0.5"
after reading documentation more closely, found missing calling stop().
as stated on documentation
oncomplete - [optional] - function fire when job complete, when stopped.
so manually calling stop() on completion , getting callback. code looks like:
cronwrapper.prototype.pushnotificationcron = function() {     // change console winston in real implementation.     console.log('creating job');     var jobpattern = '*/10 * * * * *';     var job = new cronjob(jobpattern, function(){         var date = new date();         console.log('cron started on \t' + date);         job.stop();     }, onjobcompleted, false);     console.log('starting job');     job.start(); };  // var onjobstarted = function(){ //  var date = new date(); //  console.log('cron started on \t' + date);  // };  var onjobcompleted = function(){     winston.info('job completed:'); }; output
cron started on     tue dec 16 2014 13:13:30 gmt+0530 (ist) info: job completed: 
Comments
Post a Comment