class Sidekiq::Stats::History
Public Class Methods
new(days_previous, start_date = nil)
click to toggle source
# File lib/sidekiq/api.rb, line 165 def initialize(days_previous, start_date = nil) @days_previous = days_previous @start_date = start_date || Time.now.utc.to_date end
Public Instance Methods
failed()
click to toggle source
# File lib/sidekiq/api.rb, line 174 def failed @failed ||= date_stat_hash("failed") end
processed()
click to toggle source
# File lib/sidekiq/api.rb, line 170 def processed @processed ||= date_stat_hash("processed") end
Private Instance Methods
date_stat_hash(stat)
click to toggle source
# File lib/sidekiq/api.rb, line 180 def date_stat_hash(stat) i = 0 stat_hash = {} keys = [] dates = [] while i < @days_previous date = @start_date - i datestr = date.strftime("%Y-%m-%d") keys << "stat:#{stat}:#{datestr}" dates << datestr i += 1 end begin Sidekiq.redis do |conn| conn.mget(keys).each_with_index do |value, idx| stat_hash[dates[idx]] = value ? value.to_i : 0 end end rescue Redis::CommandError # mget will trigger a CROSSSLOT error when run against a Cluster # TODO Someone want to add Cluster support? end stat_hash end