Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between node-cron module and Heroku Scheduler

I have a node app running on Heroku.
I want some jobs to run periodically every few seconds, in order to fetch data from an external MySQL DB to my MongoDB.
After extensive search I have found a lot of ways to do this.

My problem is I cannot fully understand the difference between cron-module and the Heroku Scheduler and the pros and cons.

Some differences I spotted:
If I use Heroku Scheduler there is a limit of 10 minutes minimum.
If I use node-cron module, I will run it in my main index.js file and it will run every few seconds if I want it to.

But how are those two methods affected when running multiple dynos?
In which case the scripts will run multiple duplicated times?

like image 784
anestis Avatar asked May 23 '26 03:05

anestis


1 Answers

node-cron will run the function at the time specified within the instance of your app that is currently running. You can schedule these with much greater precision.

Heroku Scheduler will spin up a new dyno and run the function. Once the function finishes, the dyno will spin down (i.e. shut down). You can schedule these with less precision.

If you're using multiple dynos:

  • Heroku Scheduler will not run duplicate commands.
  • node-cron will run on each instance which it has been called (likely every instance) so there will be concurrent (duplicate) functions running.
like image 148
Jacob Avatar answered May 26 '26 12:05

Jacob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!