class Sidekiq::Statistic::Workers

Constants

JOB_STATES

Public Instance Methods

display() click to toggle source
# File lib/sidekiq/statistic/statistic/workers.rb, line 8
def display
  worker_names.map do |worker|
    {
      name: worker,
      last_job_status: last_job_status_for(worker),
      number_of_calls: number_of_calls(worker),
      queue: last_queue(worker),
      runtime: runtime_statistic(worker).values_hash
    }
  end
end
display_per_day(worker_name) click to toggle source
# File lib/sidekiq/statistic/statistic/workers.rb, line 20
def display_per_day(worker_name)
  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/statistic/statistic/workers.rb, line 60
def last_job_status_for(worker)
  statistic_for(worker)
    .select(&:any?)
    .last[:last_job_status]
end
last_queue(worker) click to toggle source
# File lib/sidekiq/statistic/statistic/workers.rb, line 66
def last_queue(worker)
  statistic_for(worker).last[:queue]
end
number_of_calls(worker) click to toggle source
# File lib/sidekiq/statistic/statistic/workers.rb, line 44
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/statistic/statistic/workers.rb, line 54
def number_of_calls_for(state, worker)
  statistic_for(worker)
    .select(&:any?)
    .map{ |hash| hash[state] }.inject(:+) || 0
end
runtime_for_day(worker_name, worker_data) click to toggle source
# File lib/sidekiq/statistic/statistic/workers.rb, line 38
def runtime_for_day(worker_name, worker_data)
  runtime_statistic(worker_name, worker_data)
    .values_hash
    .merge!(last: worker_data[:last_time])
end
runtime_statistic(worker, values = nil) click to toggle source
# File lib/sidekiq/statistic/statistic/workers.rb, line 70
def runtime_statistic(worker, values = nil)
  Runtime.new(self, worker, values)
end