Class: SidekiqHerokuScaler::Heroku::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq-heroku-scaler/heroku/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(heroku_app_name, heroku_token) ⇒ Client

Returns a new instance of Client.



9
10
11
12
# File 'lib/sidekiq-heroku-scaler/heroku/client.rb', line 9

def initialize(heroku_app_name, heroku_token)
  @heroku_app_name = heroku_app_name
  @heroku_token = heroku_token
end

Instance Method Details

#formation_for(worker_name) ⇒ Object



18
19
20
21
22
# File 'lib/sidekiq-heroku-scaler/heroku/client.rb', line 18

def formation_for(worker_name)
  SidekiqHerokuScaler::Heroku::Formation.new(
    formations.detect { |formation| formation['type'] == worker_name.to_s } || {}
  )
end

#formationsObject



14
15
16
# File 'lib/sidekiq-heroku-scaler/heroku/client.rb', line 14

def formations
  @formations ||= formation.list(heroku_app_name)
end

#sidekiq_workersObject



24
25
26
27
# File 'lib/sidekiq-heroku-scaler/heroku/client.rb', line 24

def sidekiq_workers
  @sidekiq_workers ||= formations.select { |formation| formation['command'].include?('sidekiq') }
                                 .map { |formation| formation['type'] }
end

#update_formation(formation_id, quantity) ⇒ Object



29
30
31
# File 'lib/sidekiq-heroku-scaler/heroku/client.rb', line 29

def update_formation(formation_id, quantity)
  formation.update(heroku_app_name, formation_id, quantity: quantity)
end