Scheduled jobs in Rails 5 and Heroku

This tutorial will show you how to add a scheduled job to Rails 5 and Heroku. It only takes a few minutes.

  1. To run scheduled jobs on Heroku, they require you to enable their free add-on, Heroku Scheduler. Add it to your app via the command line:
    heroku addons:create scheduler:standard
  2. Inside your Rails 5 app, create a file inside libs/tasks called scheduler.rake.
    desc "Short description of the task goes here"
    task hello_world: :environment do
      puts "Hello world!"
  3. Now, let’s tell scheduler to run hello_world. Open the scheduler:
    heroku addons:open scheduler
  4. Type rake hello_world into the input field and set how often you want it to recur.

And that’s it! You now have a scheduled job that recurs as often as you’d like.