Module: Resque::Plugins::HerokuAutoscaler

Defined in:
lib/resque/plugins/heroku_autoscaler/config.rb,
lib/resque/plugins/resque_heroku_autoscaler.rb,
lib/resque/plugins/heroku_autoscaler/version.rb

Defined Under Namespace

Modules: Config

Constant Summary collapse

VERSION =
"0.2.3"
@@heroku_client =
nil

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.config {|Resque::Plugins::HerokuAutoscaler::Config| ... } ⇒ Object



35
36
37
# File 'lib/resque/plugins/resque_heroku_autoscaler.rb', line 35

def self.config
  yield Resque::Plugins::HerokuAutoscaler::Config
end

Instance Method Details

#after_enqueue_scale_workers_up(*args) ⇒ Object



8
9
10
# File 'lib/resque/plugins/resque_heroku_autoscaler.rb', line 8

def after_enqueue_scale_workers_up(*args)
  calculate_and_set_workers
end

#after_perform_scale_workers_down(*args) ⇒ Object



12
13
14
# File 'lib/resque/plugins/resque_heroku_autoscaler.rb', line 12

def after_perform_scale_workers_down(*args)
  calculate_and_set_workers
end

#current_workersObject



26
27
28
# File 'lib/resque/plugins/resque_heroku_autoscaler.rb', line 26

def current_workers        
  heroku_client.info(Resque::Plugins::HerokuAutoscaler::Config.heroku_app)[:workers].to_i
end

#heroku_clientObject



30
31
32
33
# File 'lib/resque/plugins/resque_heroku_autoscaler.rb', line 30

def heroku_client
  @@heroku_client || @@heroku_client = Heroku::Client.new(Resque::Plugins::HerokuAutoscaler::Config.heroku_user,
                                                          Resque::Plugins::HerokuAutoscaler::Config.heroku_pass)
end

#on_failure_scale_workers(*args) ⇒ Object



16
17
18
# File 'lib/resque/plugins/resque_heroku_autoscaler.rb', line 16

def on_failure_scale_workers(*args)
  calculate_and_set_workers
end

#set_workers(number_of_workers) ⇒ Object



20
21
22
23
24
# File 'lib/resque/plugins/resque_heroku_autoscaler.rb', line 20

def set_workers(number_of_workers)
  if number_of_workers != current_workers
    heroku_client.set_workers(Resque::Plugins::HerokuAutoscaler::Config.heroku_app, number_of_workers)
  end
end