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:
parent
8f36e26453
commit
22072262d7
1 changed files with 48 additions and 46 deletions
|
@ -23,56 +23,10 @@ module Sidekiq
|
|||
stat 'dead_size'
|
||||
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!
|
||||
stats
|
||||
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)
|
||||
all = %w(failed processed)
|
||||
stats = stats.empty? ? all : all & stats.flatten.compact.map(&:to_s)
|
||||
|
@ -112,6 +66,54 @@ module Sidekiq
|
|||
queues.values.inject(&:+) || 0
|
||||
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
|
||||
def initialize(days_previous, start_date = nil)
|
||||
@days_previous = days_previous
|
||||
|
|
Loading…
Reference in a new issue