Class: Resque::Plugins::JobHistory::JobList

Inherits:
HistoryDetails show all
Defined in:
lib/resque/plugins/job_history/job_list.rb

Overview

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.

Constant Summary

Constants inherited from HistoryDetails

HistoryDetails::MAX_LINEAR_HISTORY, HistoryDetails::NAME_SPACE

Instance Attribute Summary

Attributes inherited from HistoryDetails

#class_name

Instance Method Summary collapse

Methods inherited from HistoryDetails

class_list_page_size, class_list_page_size=, #class_name_valid?, #clean_old_running_jobs, #finished_jobs, #job_history_base_key, job_history_key, #last_run, #linear_jobs, linear_page_size, linear_page_size=, #max_concurrent_jobs, max_linear_jobs, max_linear_jobs=, #num_finished_jobs, #num_running_jobs, #page_size, #redis, #running_jobs, #total_failed_jobs, #total_finished_jobs, #total_run_jobs

Constructor Details

#initializeJobList

Returns a new instance of JobList.



10
11
12
# File 'lib/resque/plugins/job_history/job_list.rb', line 10

def initialize
  super("")
end

Instance Method Details

#job_classesObject



36
37
38
# 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) ⇒ Object



40
41
42
# 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) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# 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) ⇒ Object



14
15
16
17
18
19
20
21
22
# 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