Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku and node-cron?

So I know Heroku's free dynos 'wind down' when there isn't any traffic to them– how would this effect the cron jobs that I've implemented using the node-cron module?

like image 566
dshidham Avatar asked Aug 20 '16 19:08

dshidham


People also ask

Does node cron work on Heroku?

Cronjobs can be run locally via npm package — node-cron. But in Heroku, Jobs scheduled by node_cron won't run when your free dynos are sleeping, that is if cron execution will be scheduled at the time when your server would be offline, then it won't work.

What is Heroku scheduler?

Scheduler is a free add-on for running jobs on your app at scheduled time intervals, much like cron in a traditional server environment. While Scheduler is a free add-on, it executes scheduled jobs via one-off dynos that will count towards your monthly usage. Scheduler job execution is expected but not guaranteed.

Is Heroku scheduler reliable?

Reliable delivery Heroku Scheduler is a free add-on, but it doesn't guarantee that jobs will be executed at their scheduled time, or at all for that matter. While it is rare, the possibility that a job may be skipped or run twice does exist.


2 Answers

Jobs scheduled by node_cron won't run when your free dynos are sleeping.

As an alternative, you can use the Heroku Scheduler add-on to schedule your cron jobs. That will trigger one-off dynos to run your cron jobs. Provided you don't exceed your monthly allowance of free dyno hours, you will be able to run your cron jobs for free.

like image 126
Yoni Rabinovitch Avatar answered Sep 30 '22 00:09

Yoni Rabinovitch


Probably they won't work as you expect in 100%. I mean, if cron execution will be scheduled at the time when your server would be offline, then it won't work. Hobby Dynos on Heroku power-up only at HTTP request and shutdown after some period of inactivity, they won't boot because of cron.

like image 22
Rafal Wiliński Avatar answered Sep 30 '22 00:09

Rafal Wiliński