Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I was writing a scheduler. I need to run a process every x minutes. The scheduling module I was using had functionality I could utilize that would run something at every time I specify. For example, I could run something at every 17 minutes past the hour and 51 minutes past the hour (twice every hour) by doing this:
- rule.minute = [17, 51];
- So, in order to run something every x minutes I did this:
- var intervals = [];
- var interval = Math.ceil(60 / x);
- for(var i = 0; i < x; i++) {
- intervals.push(interval * i);
- }
- rule.minute = intervals
- So, if we wanted to do it every 9 minutes (x = 9) we have Math.ceil(60 / 9) = 7
- After the above code executes rules.minute = [0, 7, 14, 21, 28, 35, 42, 49, 56]
- rules.minute.length = 9! This is what we want, right? This is what I thought at work today LOL
- My logic error is that, instead of running the process every x minutes, I'm running it x times every hour :/
- oops
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement