lib/sidekiq-heroku-scaler/worker.rb in sidekiq-heroku-scaler-0.3.5 vs lib/sidekiq-heroku-scaler/worker.rb in sidekiq-heroku-scaler-0.4.0

- old
+ new

@@ -3,10 +3,12 @@ require 'sidekiq' require 'sidekiq-heroku-scaler/sidekiq_config' module SidekiqHerokuScaler class Worker + attr_reader :worker_name + def initialize(worker_name, formation) @worker_name = worker_name @formation = formation end @@ -32,13 +34,17 @@ def queues_size queues.sum { |queue| Sidekiq::Queue.new(queue).size } end + def processes + @processes ||= Sidekiq::ProcessSet.new.select { |process| process.identity.match?(/\A#{worker_name}\./) } + end + private - attr_reader :formation, :worker_name + attr_reader :formation def build_process command = formation.command.gsub(/.*sidekiq(\s|\z)/, '').split sideki_config = SidekiqHerokuScaler::SidekiqConfig.new(command) Sidekiq::Process.new(sideki_config.config) @@ -46,14 +52,10 @@ 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 + @process ||= processes.first || build_process end end end