class SidekiqHerokuScaler::Manager
Attributes
heroku_client[R]
strategy[R]
workers[R]
Public Class Methods
new(heroku_app_name:, heroku_token:, workers:, strategy:)
click to toggle source
# File lib/sidekiq-heroku-scaler/manager.rb, line 8 def initialize(heroku_app_name:, heroku_token:, workers:, strategy:) @heroku_client = SidekiqHerokuScaler::Heroku::Client.new(heroku_app_name, heroku_token) @strategy = strategy @workers = workers end
Public Instance Methods
perform()
click to toggle source
# File lib/sidekiq-heroku-scaler/manager.rb, line 14 def perform autoscalable_workers.each(&method(:autoscale_one)) end
Private Instance Methods
autoscalable_workers()
click to toggle source
# File lib/sidekiq-heroku-scaler/manager.rb, line 41 def autoscalable_workers heroku_client.sidekiq_workers & workers end
autoscale_one(worker_name)
click to toggle source
# File lib/sidekiq-heroku-scaler/manager.rb, line 22 def autoscale_one(worker_name) formation = heroku_client.formation_for(worker_name) return if formation.blank? sidekiq_worker = SidekiqHerokuScaler::Worker.new(worker_name, formation) process_formation(sidekiq_worker) end
process_formation(sidekiq_worker)
click to toggle source
# File lib/sidekiq-heroku-scaler/manager.rb, line 31 def process_formation(sidekiq_worker) if strategy.increase?(sidekiq_worker) heroku_client.update_formation(sidekiq_worker.formation_id, strategy.safe_quantity(sidekiq_worker.quantity + strategy.inc_count)) elsif strategy.decrease?(sidekiq_worker) heroku_client.update_formation(sidekiq_worker.formation_id, strategy.safe_quantity(sidekiq_worker.quantity - strategy.dec_count)) end end