Using the Heroku scheduler
It is easy to set up a keep-alive dyno ping using the Heroku scheduler. If you are a Ruby developer, you can create a rake task as follows, for an automated ping to your web dyno:
- Write the following script:
desc "Pings YOUR_HEROKU_APP_URL to keep a dyno alive" task :wakeup_dyno do require "net/http" if ENV['YOUR_HEROKU_APP_URL'] uri = URI(ENV['YOUR_HEROKU_APP_URL']) Net::HTTP.get_response(uri) end end
- Add
YOUR_HEROKU_APP_URL
to your Heroku environment:$ heroku config:add YOUR_HEROKU_APP_URL=https://yourherokuapp.herokuapp.com
- Now, set up the Heroku scheduler:
$ heroku addons:add scheduler:standard $ heroku addons:open scheduler
That last command should open the scheduler interface in your browser.
- Set up your
wakeup_dyno ...
Get Heroku Cloud Application Development now with O’Reilly online learning.
O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.