Advertisement
pAc0tAc019

Untitled

Feb 7th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. 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:
  2.  
  3. rule.minute = [17, 51];
  4.  
  5. So, in order to run something every x minutes I did this:
  6.  
  7. var intervals = [];
  8. var interval = Math.ceil(60 / x);
  9.  
  10. for(var i = 0; i < x; i++) {
  11. intervals.push(interval * i);
  12. }
  13.  
  14. rule.minute = intervals
  15.  
  16. So, if we wanted to do it every 9 minutes (x = 9) we have Math.ceil(60 / 9) = 7
  17.  
  18. After the above code executes rules.minute = [0, 7, 14, 21, 28, 35, 42, 49, 56]
  19.  
  20. rules.minute.length = 9! This is what we want, right? This is what I thought at work today LOL
  21.  
  22. My logic error is that, instead of running the process every x minutes, I'm running it x times every hour :/
  23.  
  24. oops
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement