Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to schedule Heroku's (maintenance mode or recharge) at specific time of the day?

I'm trying to keep my Heroku (free) application awake during daytime. I don't really care if it sleeps late at night.

The old technique of continuously pinging the app is no longer a valid solution because since 2015, all free-app's have to sleep at least 6 hours a day.

I'd like to know if any of you guys figured this out before.

I need to schedule the recharge state or maintenance mode in a specific time range.

Let's make this question and an up-to-date resource of accomplishing this task.

Please submit only constructive ideas.

like image 692
Cristian Elias Avatar asked Jul 25 '15 16:07

Cristian Elias


People also ask

How do I put Heroku app in maintenance mode?

To perform the maintenance, run the heroku pg:maintenance:run DATABASE --force -a sushi command at any time before your scheduled maintenance.

How do I schedule a heroku Dyno hour?

On the Scheduler Dashboard, click “Add Job…”, enter a task, select a frequency, dyno size, and next run time. Note that the next run time for daily jobs is in UTC.

How do you keep Heroku Dyno awake?

NewRelic Availability Monitoring If you install the NewRelic Heroku Addon you can set up availability monitoring. You provide a URL which NewRelic pings every 30 seconds, therefore keeping your app awake.

Can you run cron jobs on Heroku?

Cron To Go is an add-on created for Heroku users to run scheduled jobs based on one-off dynos using cron expressions. Cron To Go combines the simplicity of using cron to schedule jobs with the scale and elasticity of the cloud.


2 Answers

You can just scale it down for the six hours you want it to be asleep:

heroku scale web=0

Then scale it back up when you want to wake it up:

heroku scale web=1

There are a lot of ways to implement this; a script on some other machine would work fine, but you could probably also use the Heroku Platform API and a scheduler service:

  • https://devcenter.heroku.com/articles/platform-api-reference#formation
  • https://devcenter.heroku.com/articles/scheduler

disclosure: I'm the Node.js Platform Owner at Heroku

like image 107
hunterloftis Avatar answered Nov 11 '22 16:11

hunterloftis


There is also this add-on: https://devcenter.heroku.com/articles/process-scheduler

At first I thought it wasn't working as it doesn't seem to necessarily run right at the top of the hour, but other than that it's been working really well for me and allows me to sleep my app overnight.

like image 26
riebeekn Avatar answered Nov 11 '22 16:11

riebeekn