Saturday, 15 April 2017

How to schedule jobs to run at different times for different users

I am building a feature that allows the user to schedule a report to be generated by the server.

i.e. User A wants to schedule the report to be generated and emailed to him at 5 PM every day whereas User B wants to schedule the same at 10 AM every day.

There can be many users wanting the job to run at any time of their choosing.

I see there is something called node-schedule: https://www.npmjs.com/package/node-sched...

where you can do this:

var schedule = require('node-schedule'); 

var j = schedule.scheduleJob('42 * * * *', function(){ 
    console.log('The answer to life, the universe, and everything!'); 
}); 

to execute a cron job when the minute is 42 of each hour.

Something like this might work if the system only has one user, but for multiple users, I can't hardcode the time to schedule the job. Any suggestion?



via Sam

No comments:

Post a Comment