How to add 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. First, open it with this command:

    heroku addons:open scheduler
  4. Now we’ll create our first job.

    • Under Schedule, set how often you’d like this task to run. (If you want to create a job that recurs weekly, you can refer to my post on running Heroku’s Scheduler weekly.)
    • Under Run Command, type rake hello_world (or the name of your task from Step 2).

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

About the author

I'm Mark Thomas Miller, a full stack engineer and designer currently working at ConvertKit. (We're hiring!) People like Arnold Schwarzenegger, Lindsey Stirling, and Tim Ferriss use features I've built to connect with their fans. I'm currently geeking out about Svelte, mechanical keyboards, and minimalist UI design, and replaying Ocarina of Time.