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

Protect private methods

This commit is contained in:
Ismael Abreu 2015-01-16 23:25:42 +00:00
parent 8f36e26453
commit 22072262d7

View file

@ -23,56 +23,10 @@ module Sidekiq
stat 'dead_size' stat 'dead_size'
end end
def stats(*only)
all = %w(processed failed queues enqueued scheduled_size retry_size dead_size)
metrics = only.any? ? only : all
if @all_stats
@all_stats.slice(*metrics)
else
if metrics == all
@all_stats = load_stats(*all)
else
load_stats(*metrics)
end
end
end
def fetch_stats! def fetch_stats!
stats stats
end end
def stat(s)
stats(s)[s]
end
def load_stats(*metrics)
read_pipelined = %w(processed failed scheduled_size retry_size dead_size) & metrics
loaded_stats = {}
if read_pipelined.any?
results = Sidekiq.redis do |conn|
conn.pipelined do
read_pipelined.each do |key|
case key
when 'processed' then conn.get('stat:processed')
when 'failed' then conn.get('stat:failed')
when 'scheduled_size' then conn.zcard('schedule')
when 'retry_size' then conn.zcard('retry')
when 'dead_size' then conn.zcard('dead')
end
end
end
end
read_pipelined.zip(results).each {|metric, v| loaded_stats[metric] = v.to_i }
end
(metrics - read_pipelined).each do |metric|
loaded_stats[metric] = public_send(metric)
end
loaded_stats
end
def reset(*stats) def reset(*stats)
all = %w(failed processed) all = %w(failed processed)
stats = stats.empty? ? all : all & stats.flatten.compact.map(&:to_s) stats = stats.empty? ? all : all & stats.flatten.compact.map(&:to_s)
@ -112,6 +66,54 @@ module Sidekiq
queues.values.inject(&:+) || 0 queues.values.inject(&:+) || 0
end end
private
def stats(*only)
all = %w(processed failed queues enqueued scheduled_size retry_size dead_size)
metrics = only.any? ? only : all
if @all_stats
@all_stats.slice(*metrics)
else
if metrics == all
@all_stats = load_stats(*all)
else
load_stats(*metrics)
end
end
end
def stat(s)
stats(s)[s]
end
def load_stats(*metrics)
read_pipelined = %w(processed failed scheduled_size retry_size dead_size) & metrics
loaded_stats = {}
if read_pipelined.any?
results = Sidekiq.redis do |conn|
conn.pipelined do
read_pipelined.each do |key|
case key
when 'processed' then conn.get('stat:processed')
when 'failed' then conn.get('stat:failed')
when 'scheduled_size' then conn.zcard('schedule')
when 'retry_size' then conn.zcard('retry')
when 'dead_size' then conn.zcard('dead')
end
end
end
end
read_pipelined.zip(results).each {|metric, v| loaded_stats[metric] = v.to_i }
end
(metrics - read_pipelined).each do |metric|
loaded_stats[metric] = public_send(metric)
end
loaded_stats
end
class History class History
def initialize(days_previous, start_date = nil) def initialize(days_previous, start_date = nil)
@days_previous = days_previous @days_previous = days_previous