Want a new VS Code theme?

Scheduled jobs in Rails 5 and Heroku

March 31, 2019

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.

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