javascript - Writting a reschedulable cron job in Node.js -


i using node-schedule node package write cron job. able write simple schedular want reschedulable job.

in app, users can start task specific date. can acheive below code.

var schedule = require('node-schedule'); var date = new date(2012, 11, 21, 5, 30, 0);  var j = schedule.schedulejob(date, function(){   console.log('do on scheduled date'); }); 

the problem i've how can reschedule selected scheduled job.

let's say, if user a started job run on date 10/14/2017 , created new cron job run on date 10/14/2017. user a decides change task date 1/14/2017, how identify task created user a out of multiple tasks in queue (created other users) , reschedule cron job new date i.e. 1/14/2017?

j has reschedule method can call. see https://www.npmjs.com/package/node-schedule#jobreschedulespec.

j.reschedule(new date); 

to keep track of jobs, might use object map user scheduled job.

const userjobs = {};  userjobs['user a'] = schedule.schedulejob(date, () => {   console.log('do on scheduled date');   delete userjobs['user a']; });  userjobs['user a'].reschedule(new date); 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -