1

I want to have a weekly cleanup-query run on my DB.

i'm thinking about just using setInterval(), or installing another library to schedule the task.

now i wonder, does it take up much resources to have setInterval() run for weekly events? isn't that a whole lot of overhead, constantly checking? or does it not work that way, and i can safely set and forget it without worrying?

if there is no (or very little) downside to it, i won't bother with any modules, but i don't want to choke my server with unnecessary load

user3787706
  • 659
  • 1
  • 6
  • 18
  • http://stackoverflow.com/questions/6650134/is-setinterval-cpu-intensive? – Nebula Jan 18 '16 at 13:47
  • 1
    For long term periodic tasks like that it seems to me you'd want a different, more robust service. – Pointy Jan 18 '16 at 13:47
  • 3
    Use CRON instead of `setInterval` – Tushar Jan 18 '16 at 13:47
  • I'm not sure, but I guess it does not have much impact. setInterval registers an event at specific tick. When that tick arrives, attached function is executed. – Rajesh Jan 18 '16 at 13:48
  • Bear in mind that `setInterval` (and `setTimeout`) only specifies a _minimum_ amount of time to wait. It _could_ be that a long running thing like this would slowly drift away from the time you want it to be running. As others have noted, it's not the best choice for a solution here - other ways to invoke the code at fixed intervals are better. – James Thorpe Jan 18 '16 at 13:49
  • There is [cron middleware](https://github.com/ncb000gt/node-cron/blob/master/lib/cron.js) available for Node, but is just uses `setTimeout` internally as well. – adeneo Jan 18 '16 at 14:11

0 Answers0