1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Use idiomatic ruby Array methods (#4338)

This commit is contained in:
fatkodima 2019-10-16 18:42:32 +03:00 committed by Mike Perham
parent 0b370e07b2
commit 4803d87969

View file

@ -140,13 +140,8 @@ module Sidekiq
end end
} }
i = 0 array_of_arrays = queues.zip(lengths).sort_by { |_, size| -size }
array_of_arrays = queues.each_with_object({}) { |queue, memo| Hash[array_of_arrays]
memo[queue] = lengths[i]
i += 1
}.sort_by { |_, size| size }
Hash[array_of_arrays.reverse]
end end
end end
end end
@ -168,18 +163,12 @@ module Sidekiq
private private
def date_stat_hash(stat) def date_stat_hash(stat)
i = 0
stat_hash = {} stat_hash = {}
keys = [] dates = @start_date.downto(@start_date - @days_previous + 1).map { |date|
dates = [] date.strftime("%Y-%m-%d")
}
while i < @days_previous keys = dates.map { |datestr| "stat:#{stat}:#{datestr}" }
date = @start_date - i
datestr = date.strftime("%Y-%m-%d")
keys << "stat:#{stat}:#{datestr}"
dates << datestr
i += 1
end
begin begin
Sidekiq.redis do |conn| Sidekiq.redis do |conn|
@ -523,7 +512,7 @@ module Sidekiq
else else
# multiple jobs with the same score # multiple jobs with the same score
# find the one with the right JID and push it # find the one with the right JID and push it
hash = results.group_by { |message| matched, nonmatched = results.partition { |message|
if message.index(jid) if message.index(jid)
msg = Sidekiq.load_json(message) msg = Sidekiq.load_json(message)
msg["jid"] == jid msg["jid"] == jid
@ -532,12 +521,12 @@ module Sidekiq
end end
} }
msg = hash.fetch(true, []).first msg = matched.first
yield msg if msg yield msg if msg
# push the rest back onto the sorted set # push the rest back onto the sorted set
conn.multi do conn.multi do
hash.fetch(false, []).each do |message| nonmatched.each do |message|
conn.zadd(parent.name, score.to_f.to_s, message) conn.zadd(parent.name, score.to_f.to_s, message)
end end
end end
@ -785,10 +774,9 @@ module Sidekiq
# the hash named key has an expiry of 60 seconds. # the hash named key has an expiry of 60 seconds.
# if it's not found, that means the process has not reported # if it's not found, that means the process has not reported
# in to Redis and probably died. # in to Redis and probably died.
to_prune = [] to_prune = procs.select.with_index { |proc, i|
heartbeats.each_with_index do |beat, i| heartbeats[i].nil?
to_prune << procs[i] if beat.nil? }
end
count = conn.srem("processes", to_prune) unless to_prune.empty? count = conn.srem("processes", to_prune) unless to_prune.empty?
end end
count count