class Sidekiq::Stats::History
Public Class Methods
Source
# File lib/sidekiq/api.rb, line 188 def initialize(days_previous, start_date = nil, pool: nil) # we only store five years of data in Redis raise ArgumentError if days_previous < 1 || days_previous > (5 * 365) @days_previous = days_previous @start_date = start_date || Time.now.utc.to_date end
Public Instance Methods
Source
# File lib/sidekiq/api.rb, line 199 def failed @failed ||= date_stat_hash("failed") end
Source
# File lib/sidekiq/api.rb, line 195 def processed @processed ||= date_stat_hash("processed") end
Private Instance Methods
Source
# File lib/sidekiq/api.rb, line 205 def date_stat_hash(stat) stat_hash = {} dates = @start_date.downto(@start_date - @days_previous + 1).map { |date| date.strftime("%Y-%m-%d") } keys = dates.map { |datestr| "stat:#{stat}:#{datestr}" } Sidekiq.redis do |conn| conn.mget(keys).each_with_index do |value, idx| stat_hash[dates[idx]] = value ? value.to_i : 0 end end stat_hash end