Class: SidekiqAutoscale::HerokuAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_autoscale/adapters/heroku_adapter.rb

Instance Method Summary collapse

Constructor Details

#initializeHerokuAdapter

Returns a new instance of HerokuAdapter.



5
6
7
8
9
10
# File 'lib/sidekiq_autoscale/adapters/heroku_adapter.rb', line 5

def initialize
  require "platform-api"
  @app_name = SidekiqAutoscale.adapter_config[:app_name]
  @dyno_name = SidekiqAutoscale.adapter_config[:worker_dyno_name]
  @client = PlatformAPI.connect_oauth(SidekiqAutoscale.adapter_config[:api_key])
end

Instance Method Details

#worker_countObject



12
13
14
15
16
17
18
19
20
# File 'lib/sidekiq_autoscale/adapters/heroku_adapter.rb', line 12

def worker_count
  @client.formation.list(@app_name)
         .select {|i| i["type"] == @dyno_name }
         .map {|i| i["quantity"] }
         .reduce(0, &:+)
rescue Excon::Errors::Error => e
  SidekiqAutoscale.on_scaling_error(e)
  0
end

#worker_count=(val) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/sidekiq_autoscale/adapters/heroku_adapter.rb', line 22

def worker_count=(val)
  return if val == worker_count

  @client.formation.update(@app_name, @dyno_name, quantity: val)
  SidekiqAutoscale.logger.info("[SIDEKIQ_SCALE][HEROKU_ACTION] Set new worker count to #{val} (previously #{worker_count})")
rescue Excon::Errors::Error, Heroku::API::Errors::Error => e
  SidekiqAutoscale.on_scaling_error(e)
end