I have to implement cron jobs in to my MMO browser game. Its like in Travian game - you build something, and wait few minutes or hours.. But the problem is, that cron job shedulers made to be sheduled every second/minute/day etc.. But in my game i need to shedule thousands of the same jobs, which must run separately and after some unique time to be released. So far i am unlucky with that idea. I am using Node.js and I just tried so many node shedulers, they seem are not supposed to have thousands of jobs.. I can run few unique only. I trough maybe then i can make like - cron job, which runs every 1 second and checks the Redis DB for any finished proccess. But that sounds crazy.. if i have few jobs only and they are in 24 hous only, my server checks that every 1 second.. Any ideas what should i do?
So far, the best option would be to remove cron jobs. I was doing some my processes without cron jobs. But other processes were really hard to calculate, and it was much easier with cron jobs. But i trough deeper and i think it is possible to calculate eveyrthing and simulate everything without cron jobs.
For example, the user has ressources inside Stats model. And i have hourly ressource income there. If the user wants to build anything, for example, traps, i have to recalculate the user ressources and save new value, set the new updatedAt. This is how i am updating my user ressources (inside Stats model), when some user wants to build a trap.
Stats.findOne({user_id: user_id}).exec(function (err, newstats){
var time_in_ms = (new Date()).getTime() - new Date(newstats.updatedAt).getTime();
var ressources_per_second = (newstats.base_income + newstats.field_income) / 60 / 60;
var current_ressources = newstats.resources + parseInt(time_in_ms / 1000 * ressources_per_second) - traps_price;
if(current_ressources < traps_price) return res.ok();
Stats.update(newstats.id, {resources: current_ressources});
});