class Sidekiq::Stats::History

Public Class Methods

new(days_previous, start_date = nil) click to toggle source
# File lib/sidekiq/api.rb, line 163
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 172
def failed
  @failed ||= date_stat_hash("failed")
end
processed() click to toggle source
# File lib/sidekiq/api.rb, line 168
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 178
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}" }

  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