Sha256: d61fc9962ef8dbc006c397b62132122da9013d5ab0a364c074555c3e07f19100
Contents?: true
Size: 1.2 KB
Versions: 1
Compression:
Stored size: 1.2 KB
Contents
# frozen_string_literal: true require 'sidekiq-heroku-scaler/heroku/client' require 'sidekiq-heroku-scaler/worker' module SidekiqHerokuScaler class Manager 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 def perform autoscalable_workers.each(&method(:autoscale_one)) end private attr_reader :heroku_client, :strategy, :workers 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 def process_formation(sidekiq_worker) if strategy.increase?(sidekiq_worker) heroku_client.update_formation(sidekiq_worker.formation_id, sidekiq_worker.quantity + 1) elsif strategy.decrease?(sidekiq_worker) heroku_client.update_formation(sidekiq_worker.formation_id, sidekiq_worker.quantity - 1) end end def autoscalable_workers heroku_client.sidekiq_workers & workers end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sidekiq-heroku-scaler-0.1.0 | lib/sidekiq-heroku-scaler/manager.rb |