Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 28th, 2012  |  syntax: None  |  size: 0.58 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # Inspired by http://verboselogging.com/2010/07/30/auto-scale-your-resque-workers-on-heroku
  2.  
  3. module HerokuAutoscale
  4.   module Scaler
  5.     class << self
  6.       @@heroku = Heroku::Client.new(ENV['HEROKU_USER'], ENV['HEROKU_PASS'])
  7.  
  8.       def workers
  9.         @@heroku.info(ENV['HEROKU_APP'])[:workers].to_i
  10.       end
  11.  
  12.       def workers=(qty)
  13.         @@heroku.set_workers(ENV['HEROKU_APP'], qty)
  14.       end
  15.  
  16.       def job_count
  17.         Delayed::Job.count
  18.       end
  19.     end
  20.   end
  21.  
  22.   def after_perform_scale_down
  23.     Scaler.workers = 0
  24.   end
  25.  
  26.   def after_enqueue_scale_up
  27.     Scaler.workers = 1
  28.   end
  29.  
  30. end