node-cron icon indicating copy to clipboard operation
node-cron copied to clipboard

Support for multi-instances of the same node server

Open ilaif opened this issue 11 years ago • 5 comments

In case you have a node server distributed across multiple machines, cores and/or threads, then each process will launch the cron job and then you get multiple executions of the same task.

Is there a solution to this? How would you make the cronjob be at some shared state with the other nodes so that only one actually executes the scheduled cronjob?

Thanks, Ilai.

ilaif avatar Jun 16 '15 11:06 ilaif

Just a thought, but perhaps you could configure the jobs to only run on the master (of the clusters).

royhowie avatar Jun 19 '15 10:06 royhowie

Actually I'm using pm2 for running the clusters so the master is actually the pm2.

However I ran into https://github.com/TheDeveloper/warlock which uses a redis server for a locking system, so that only one node will win and execute the task.

ilaif avatar Jun 19 '15 15:06 ilaif

Thanks for the link. That helped me a lot :)

jsdream avatar Jul 16 '15 09:07 jsdream

We seem to have also run into this issue, with our cron jobs running on multiple Heroku dynos -- any suggestions / ideas to workaround this issue?

markcarey avatar Aug 13 '15 14:08 markcarey

The way I'd approach this is similar to how @ilaif did. You need some centralized approach and can either do this with a db or some central api server that manages locks for you.

As it stands this module will not do those things, but I do see value in it. Just not within this module itself. I want to keep it pretty light on purpose.

ncb000gt avatar Oct 24 '15 17:10 ncb000gt