Sha256: caed3b7fecb9947ef8aba064c6ef80420167532b4543b656f9b6f5221cf815d7
Contents?: true
Size: 1.23 KB
Versions: 3
Compression:
Stored size: 1.23 KB
Contents
# frozen_string_literal: true require 'sidekiq' require 'sidekiq-heroku-scaler/sidekiq_config' module SidekiqHerokuScaler class Worker def initialize(worker_name, formation) @worker_name = worker_name @formation = formation end def concurrency process['concurrency'] || 0 end def formation_id formation.id end def quantity formation.quantity end def jobs_running? Sidekiq::Workers.new.any? { |_process_id, _thread_id, work| queues.include?(work['queue']) } end def latency queues.sum { |queue| Sidekiq::Queue.new(queue).latency } end def queues_size queues.sum { |queue| Sidekiq::Queue.new(queue).size } end private attr_reader :formation, :worker_name def build_process command = formation.command.gsub(/.*sidekiq(\s|\z)/, '').split sideki_config = SidekiqHerokuScaler::SidekiqConfig.new(command) Sidekiq::Process.new(sideki_config.config) end def queues process['queues'] || [] end def process_set @process_set ||= Sidekiq::ProcessSet.new end def process @process ||= process_set.detect { |p| p.identity.match(/\A#{worker_name}\./) } || build_process end end end
Version data entries
3 entries across 3 versions & 1 rubygems