Book Image

Heroku Cloud Application Development

By : Anubhav Hanjura
Book Image

Heroku Cloud Application Development

By: Anubhav Hanjura

Overview of this book

Table of Contents (17 chapters)
Heroku Cloud Application Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 task to run once an hour and run it:

    $ rake wakeup_dyno