This tutorial will show you how to add a scheduled job to Rails 5 and Heroku. It only takes a few minutes.
- 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
- 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!" end
- Now, let’s tell scheduler to run
hello_world. Open the scheduler:
heroku addons:open scheduler
rake hello_worldinto 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.