class Sidekiq::History::Statistic
Constants
- JOB_STATES
Public Class Methods
new(days_previous, start_date = nil)
click to toggle source
# File lib/sidekiq/history/statistic.rb, line 6 def initialize(days_previous, start_date = nil) @start_date = start_date || Time.now.utc.to_date @end_date = @start_date - days_previous end
Public Instance Methods
display()
click to toggle source
# File lib/sidekiq/history/statistic.rb, line 11 def display redis_statistic.worker_names.map do |worker| { name: worker, last_job_status: last_job_status_for(worker), number_of_calls: number_of_calls(worker), runtime: runtime_statistic(worker).values_hash } end end
display_pre_day(worker_name)
click to toggle source
# File lib/sidekiq/history/statistic.rb, line 22 def display_pre_day(worker_name) redis_statistic.hash.flat_map do |day| day.reject{ |_, workers| workers.empty? }.map do |date, workers| worker_data = workers[worker_name] next unless worker_data { date: date, failure: worker_data[:failed], success: worker_data[:passed], total: worker_data[:failed] + worker_data[:passed], last_job_status: worker_data[:last_job_status], runtime: runtime_for_day(worker_name, worker_data) } end end.compact.reverse end
last_job_status_for(worker)
click to toggle source
# File lib/sidekiq/history/statistic.rb, line 62 def last_job_status_for(worker) redis_statistic .for_worker(worker) .select(&:any?) .last[:last_job_status] end
number_of_calls(worker)
click to toggle source
# File lib/sidekiq/history/statistic.rb, line 46 def number_of_calls(worker) number_of_calls = JOB_STATES.map{ |state| number_of_calls_for state, worker } { success: number_of_calls.first, failure: number_of_calls.last, total: number_of_calls.inject(:+) } end
number_of_calls_for(state, worker)
click to toggle source
# File lib/sidekiq/history/statistic.rb, line 56 def number_of_calls_for(state, worker) redis_statistic.for_worker(worker) .select(&:any?) .map{ |hash| hash[state] }.inject(:+) || 0 end
redis_statistic()
click to toggle source
# File lib/sidekiq/history/statistic.rb, line 73 def redis_statistic RedisStatistic.new(@start_date, @end_date) end
runtime_for_day(worker_name, worker_data)
click to toggle source
# File lib/sidekiq/history/statistic.rb, line 40 def runtime_for_day(worker_name, worker_data) runtime_statistic(worker_name, worker_data[:runtime]) .values_hash .merge!(last: worker_data[:last_runtime]) end
runtime_statistic(worker, values = nil)
click to toggle source
# File lib/sidekiq/history/statistic.rb, line 69 def runtime_statistic(worker, values = nil) RuntimeStatistic.new(redis_statistic, worker, values) end