class Resque::Plugins::JobHistory::JobList

A class encompassing tasks about the jobs as a whole.

This class gets a list of the classes and can provide a summary for each.

Public Class Methods

new() click to toggle source
# File lib/resque/plugins/job_history/job_list.rb, line 10
def initialize
  super("")
end

Public Instance Methods

job_classes() click to toggle source
# File lib/resque/plugins/job_history/job_list.rb, line 36
def job_classes
  redis.smembers(Resque::Plugins::JobHistory::HistoryDetails.job_history_key)
end
job_details(class_name) click to toggle source
# File lib/resque/plugins/job_history/job_list.rb, line 40
def job_details(class_name)
  Resque::Plugins::JobHistory::HistoryDetails.new(class_name)
end
job_summaries(sort_key = :class_name, sort_order = "asc", page_num = 1, summary_page_size = Resque::Plugins::JobHistory::PAGE_SIZE) click to toggle source
# File lib/resque/plugins/job_history/job_list.rb, line 24
def job_summaries(sort_key = :class_name,
                  sort_order = "asc",
                  page_num = 1,
                  summary_page_size = Resque::Plugins::JobHistory::PAGE_SIZE)
  jobs = sorted_job_summaries(sort_key)

  page_start = (page_num - 1) * summary_page_size
  page_start = 0 if page_start > jobs.length

  (sort_order == "desc" ? jobs.reverse : jobs)[page_start..page_start + summary_page_size - 1]
end
order_param(sort_option, current_sort, current_order) click to toggle source
# File lib/resque/plugins/job_history/job_list.rb, line 14
def order_param(sort_option, current_sort, current_order)
  current_order ||= "asc"

  if sort_option == current_sort
    current_order == "asc" ? "desc" : "asc"
  else
    "asc"
  end
end

Private Instance Methods

last_run_duration_sort(last_run) click to toggle source
# File lib/resque/plugins/job_history/job_list.rb, line 84
def last_run_duration_sort(last_run)
  last_run.try(:duration) || 100.years
end
last_run_sort_value(last_run, sort_key) click to toggle source
# File lib/resque/plugins/job_history/job_list.rb, line 69
def last_run_sort_value(last_run, sort_key)
  case sort_key.to_sym
    when :start_time
      last_run_start_time_sort(last_run)
    when :duration
      last_run_duration_sort(last_run)
    when :success
      last_run_succeeded_sort(last_run)
  end
end
last_run_start_time_sort(last_run) click to toggle source
# File lib/resque/plugins/job_history/job_list.rb, line 88
def last_run_start_time_sort(last_run)
  last_run.try(:start_time) || Time.now
end
last_run_succeeded_sort(last_run) click to toggle source
# File lib/resque/plugins/job_history/job_list.rb, line 80
def last_run_succeeded_sort(last_run)
  last_run.try(:succeeded?) ? 1 : 0
end
sorted_job_summaries(sort_key) click to toggle source
# File lib/resque/plugins/job_history/job_list.rb, line 46
def sorted_job_summaries(sort_key)
  job_classes.map { |class_name| job_details(class_name) }.sort_by do |job_details|
    summary_sort_value(job_details, sort_key)
  end
end
summary_sort_value(job_details, sort_key) click to toggle source
# File lib/resque/plugins/job_history/job_list.rb, line 52
def summary_sort_value(job_details, sort_key)
  case sort_key.to_sym
    when :class_name,
        :num_running_jobs,
        :num_finished_jobs,
        :total_finished_jobs,
        :total_run_jobs,
        :max_concurrent_jobs,
        :total_failed_jobs
      job_details.public_send sort_key
    when :class_name_valid?
      job_details.class_name_valid? ? 1 : 0
    else
      last_run_sort_value(job_details.last_run, sort_key)
  end
end