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:

  1. 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
  2. Add YOUR_HEROKU_APP_URL to your Heroku environment:
    $ heroku config:add YOUR_HEROKU_APP_URL=https://yourherokuapp.herokuapp.com
    
  3. 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.

  4. Set up your wakeup_dyno ...

Get Heroku Cloud Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.