Skip to content

Instantly share code, notes, and snippets.

@robertomiranda
Forked from jfgomez86/heroku_autoscaler.rb
Created November 2, 2011 15:15
Show Gist options
  • Save robertomiranda/1333883 to your computer and use it in GitHub Desktop.
Save robertomiranda/1333883 to your computer and use it in GitHub Desktop.
Quick Dirty Heroku AutoScaling script that may save you money. Works with Delayed Job.
# Inspired by http://verboselogging.com/2010/07/30/auto-scale-your-resque-workers-on-heroku
module HerokuAutoscale
module Scaler
class << self
@@heroku = Heroku::Client.new(ENV['HEROKU_USER'], ENV['HEROKU_PASS'])
def workers
@@heroku.info(ENV['HEROKU_APP'])[:workers].to_i
end
def workers=(qty)
@@heroku.set_workers(ENV['HEROKU_APP'], qty)
end
def job_count
Delayed::Job.count
end
end
end
def after_perform_scale_down
Scaler.workers = 0
end
def after_enqueue_scale_up
Scaler.workers = 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment