-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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