Mary Briskin

Keeping Heroku Apps Awake

I host my Rails apps on Heroku, which is an awesome service.
It was becoming a problem though, that after an hour of disuse the apps would go into idle mode. Once an app is idling, the startup time ranges from 8 - 15 seconds, by which point many users just give up and click elsewhere.

I fixed this by creating yet another Rails app and writting a custom rake task that sends GET requests to all of my previous applications, keeping them from idling.
desc "This task is called by the Heroku scheduler add-on"
task :send_requests => :environment do
  urls = ['http://loggit.marytal.com', 'http://oskar.marytal.com', 'http://magnetboard.marytal.com'] # etc.
  urls.each do |url| 
    HTTParty.get(url);
  end
end
To periodically schedule these requests, I installed a Heroku add-on called Scheduler. All I had to do then was specify which rake task to run and at what frequency. Problem solved!

Lessons Learned:

  1. Difference between web and worker dynos
  2. Building custom rake tasks
  3. How to use Heroku add-ons



Side Note: If you schedule too many tasks, Heroku will start charging you - so take care to monitor your usage.