Class: Resque::Plugins::HerokuScaler::Manager::Local
- Inherits:
-
Object
- Object
- Resque::Plugins::HerokuScaler::Manager::Local
- Defined in:
- lib/resque/plugins/heroku_scaler/manager/local.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Local
constructor
A new instance of Local.
- #kill(process) ⇒ Object
- #scale_down(qty) ⇒ Object
- #scale_up(qty) ⇒ Object
- #workers ⇒ Object
- #workers=(qty) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Local
Returns a new instance of Local.
10 11 12 13 |
# File 'lib/resque/plugins/heroku_scaler/manager/local.rb', line 10 def initialize(={}) @path = [:path] || ENV['RUSH_PATH'] @processes = [] end |
Instance Method Details
#kill(process) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/resque/plugins/heroku_scaler/manager/local.rb', line 45 def kill(process) process.children.each do |child| kill(child) end process.kill end |
#scale_down(qty) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/resque/plugins/heroku_scaler/manager/local.rb', line 36 def scale_down(qty) i = 0 until i == qty or @processes.empty? process = @processes.pop kill(process) i += 1 end end |
#scale_up(qty) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/resque/plugins/heroku_scaler/manager/local.rb', line 29 def scale_up(qty) qty.times do process = Rush::Box.new[@path].bash('rake resque:work', :background => true, :env => { :BUNDLE_GEMFILE => '' }) @processes.push(process) if process end end |
#workers ⇒ Object
15 16 17 |
# File 'lib/resque/plugins/heroku_scaler/manager/local.rb', line 15 def workers @processes.length end |
#workers=(qty) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/resque/plugins/heroku_scaler/manager/local.rb', line 19 def workers=(qty) active = workers return if qty == active if qty > active scale_up(qty-active) return end scale_down(active-qty) end |