javascript - User scheduled jobs -
i allow users set schedule when particular action occur. use node server on azure. looking @ node-schedule , making use of it. contemplating running master schedule every hour checks database user specified schedules , schedule sets new schedule based on schedules users. don't know if practice, plus i'm concerned server load.
you can use node's cron
that, , accommodate in different ways. pseudocode below gives general idea.
var cronjob = require('cron').cronjob; new cronjob('0 0 * * * *', function () { // every hour // check schedules planned future, stored isodate db.getuserschedule({jobdate:{$gte:date.now()}, function(userschedules) { userschedules.foreach(sched) { // convert date string parsed cron var d=extractdayhourmin(sched) var jobtime = d[4] +' '+d[3]+' '+d[2]+' '+d[1]+' '+d[0] // setup new job var job=new cronjob(jobtime, function() { performuserjob() job.stop(); // fires once db.removeuserschedule(userschedule); })});
see https://github.com/ncb000gt/node-cron
however, possibly not best solution : creates process schedule, yes, consume more resources required. instead of scheduling schedulers, depending on granularity of possible calendar (hour, 1/2 hour, 1/4h), query db every hour (or 30 or 15mn) retrieve every date met, , trigger appropriate function.
Comments
Post a Comment