Use a Free Scheduler to Restart your Dynos in Heroku!

Dyno scheduling, plus other methods to restart Dynos in Heroku

Use a Free Scheduler to Restart your Dynos in Heroku!

The Heroku Cloud Hosting Platform is a great platform for developers, especially if you do allot of testing and development as they offer a free hosting tier for just that purpose. Free Hosting Tier.png Link: heroku.com/free

However, in order to use the platform, you need to understand the logic of how Herokus's hosting model works, which utilises a Dyno approach.

What is Dyno? In its simplest terms a Dyno is a virtual container for running apps, background services or tasks. Dyno's can also be replicated and scaled to accommodate demand and performance (similar to how Docker containers work). Dyno.png

Dyno Types

  • Web Dynos: for handling web processes
  • Worker Dynos: for handling any type of process you declare (like background jobs)
  • One-off Dynos: for handling one-off tasks, such as database migrations

Note: Dyno's will automatically restart every 24 hours, or if a new service is added/deleted to your app, or if there is an issue running your app.


In addition to the Dyno model, Heroku also uses an Ephemeral file-system.

What is a Ephemeral file-system? It is a temporary file-system, which means your app will revert back to its original repo connected state each time your apps dyno is restarted. This includes any file changes or uploads made to the app whilst is has been running.

To counteract this Heroku recommends storing persistent data in a database (PostgreSQL, MongoDB, MySql, NoSql etc) or using external AWS S3 storage containers to store the data. More details: here

However, you can also take advantage of the temporary Ephemeral file-system if you have development projects that need to be reset frequently for testing, and this is the basis on which we will be using the Scheduler.


How To Add a Free Scheduler to your App to restart your Apps Dyno

Login to Heroku and select an app you would like to use.

Once inside your app page, make sure the Overview tab is selected, then click on the Configure Add-ons link. Overview Tab

Type schedule in the Add-ons field Schedulers List

Click on Heroku Scheduler Heroku Scheduler

A popup will appear (ensure the Plan name is Standard - Free) Heroku Scheduler Popup

Click on the Submit Order Form button at the bottom of the popup. Submit Order Form

Heroku Scheduler should now appear in your Add-ons section Add-ons

Click on Heroku Scheduler Heroku Scheduler

Next you will be redirected to the settings page for the scheduler, click on the Create job button Create job A side popup will also appear with a list of options to set from the right side of the page

Side Popup

Click on the interval type you would like to use from the dropdown selection

Dropdown Selection

Now you will need to enter the Curl command used to restart your apps Dyno.

Replace <app name> with the name of your app, and <api key> with your API Key value

curl -n -X DELETE https://api.heroku.com/apps/<app name>/dynos -H "Content-Type: application/json" -H "Accept: application/vnd.heroku+json; version=3" -H "Authorization: Bearer <api key>"
  • <app name> - is located at the top of your app page (replace <app name> with your App Name) App Name

  • <api key> - goto https://dashboard.heroku.com/account, scroll down to the API Key section, then click on the Reveal button on the right side and copy the value into the CURL command (replacing <api key> with your API Key value) API Key

Enter/Paste the completed Curl command into the the Run Command field Curl Command

Then click the Save Job button at the bottom

Save Job

Your newly created job will now appear in the jobs list for the scheduler app Heroku Scheduler Job

You can also amend the job or delete it too, by clicking on one of the icons at the right New Job

Finally, to go back to the job at anytime, by going into your app, clicking on the Overview tab again, and you will see the Heroku Scheduler listed in the Installed add-ons section below. Installed add-ons

Click on Heroku Scheduler Heroku Scheduler

You will then be shown a list of all active jobs for the scheduler, where you will have the option to either edit or delete them Active Jobs


Checking App Logs

To check for issues, you can review the web logs for any app running Heroku Scheduler To do this, click on the More button at the top right of your App page, and select View logs Dropdown

The Logs will give you a real-time account of your selected running app, and highlight any issues you maybe encountering too Heroku Logs

You can also save these logs to a text file for reference later, by clicking on the Save link in the bottom right corner Save Logs


Other methods to restart your App Dyno manually

Click on the More button at the top of your app page and it will reveal a drop-down selection. Click on Restart all dynos to manually restart the Dyno(s) for your app. Restart all dynos

You will also get a popup message warning, ignore and click Restart all dynos to proceed. Proceed


Using the Heroku CLI with your Terminal Client

You can also use your own Terminal Client (VS Code, Bash etc), to directly access your logs in real-time too. However, In order to enable this feature you will first need to download the Heroku CLI. Get the Heroku CLI here

Once you have installed the Heroku CLI, type the following command in your terminal (replace <app name> with the name of your app)

heroku logs --tail --app <app name>

Terminal Logs

You can also restart the Dyno for your selected app directly from your terminal too.

heroku dyno:restart --app <app name>

Terminal Output


Disclaimer for Heroku Scheduler

The Heroku Scheduler we have been using comes with some potential bugs that should be noted (see below). However, in my opinion as long as you are only using it in a testing and development environment, and not a production one, it should be adequate to evaluate the benefits of a scheduling service for your Apps and Dynos.

Known issues & alternatives Scheduler is a free add-on with no guarantee that jobs will execute at their scheduled time, or at all:

  • In very rare instances, a job may be skipped.
  • In very rare instances, a job may run twice.

Full details of known issues and alternatives


Other Alternative Schedulers

Listed below are other alternative schedulers that maybe better suited to a production environment and offer more options for the frequency at which scheduled Jobs are run too.

Note: These alternatives are not free, but some do offer a limited free trial period for evaluation. Alternative Paid Schedulers Link to Alternative Paid Schedulers


Article Reference Links