class Sidekiq::ProcessSet
def each
def each result = Sidekiq.redis { |conn| procs = conn.sscan("processes").to_a.sort # We're making a tradeoff here between consuming more memory instead of # making more roundtrips to Redis, but if you have hundreds or thousands of workers, # you'll be happier this way conn.pipelined do |pipeline| procs.each do |key| pipeline.hmget(key, "info", "busy", "beat", "quiet", "rss", "rtt_us") end end } result.each do |info, busy, beat, quiet, rss, rtt_us| # If a process is stopped between when we query Redis for `procs` and # when we query for `result`, we will have an item in `result` that is # composed of `nil` values. next if info.nil? hash = Sidekiq.load_json(info) yield Process.new(hash.merge("busy" => busy.to_i, "beat" => beat.to_f, "quiet" => quiet, "rss" => rss.to_i, "rtt_us" => rtt_us.to_i)) end end