Class: Resque::Plugins::JobHistory::HistoryList
Overview
JobHistory cleanup functions to allow the user to cleanup Redis for histories.
Constant Summary
Resque::Plugins::JobHistory::HistoryDetails::MAX_LINEAR_HISTORY, Resque::Plugins::JobHistory::HistoryDetails::NAME_SPACE
Instance Attribute Summary collapse
#class_name
Instance Method Summary
collapse
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
#initialize(class_name, list_name, list_maximum = nil) ⇒ HistoryList
Returns a new instance of HistoryList.
10
11
12
13
14
15
|
# File 'lib/resque/plugins/job_history/history_list.rb', line 10
def initialize(class_name, list_name, list_maximum = nil)
super(class_name)
@list_name = list_name
@list_maximum = list_maximum
end
|
Instance Attribute Details
#list_name ⇒ Object
Returns the value of attribute list_name.
8
9
10
|
# File 'lib/resque/plugins/job_history/history_list.rb', line 8
def list_name
@list_name
end
|
Instance Method Details
#add_job(job_id, class_name) ⇒ Object
17
18
19
20
21
22
23
24
25
|
# File 'lib/resque/plugins/job_history/history_list.rb', line 17
def add_job(job_id, class_name)
add_to_job_history
job_count = redis.lpush(job_list_key, job_id)
save_class_information(job_id, class_name)
redis.incr(total_jobs_key)
delete_old_jobs(job_count)
end
|
#includes_job?(job_id) ⇒ Boolean
66
67
68
|
# File 'lib/resque/plugins/job_history/history_list.rb', line 66
def includes_job?(job_id)
job_ids.include?(job_id)
end
|
#job_classes_key ⇒ Object
70
71
72
|
# File 'lib/resque/plugins/job_history/history_list.rb', line 70
def job_classes_key
"#{job_history_base_key}.#{list_name}_job_classes"
end
|
#job_ids(start = 0, stop = -1)) ⇒ Object
48
49
50
|
# File 'lib/resque/plugins/job_history/history_list.rb', line 48
def job_ids(start = 0, stop = -1)
redis.lrange(job_list_key, start, stop)
end
|
#jobs(start = 0, stop = -1)) ⇒ Object
42
43
44
45
46
|
# File 'lib/resque/plugins/job_history/history_list.rb', line 42
def jobs(start = 0, stop = -1)
job_ids(start, stop).map do |job_id|
Resque::Plugins::JobHistory::Job.new(job_class(job_id), job_id)
end
end
|
#latest_job ⇒ Object
60
61
62
63
64
|
# File 'lib/resque/plugins/job_history/history_list.rb', line 60
def latest_job
job_id = redis.lrange(job_list_key, 0, 0).first
Resque::Plugins::JobHistory::Job.new(job_class(job_id), job_id) if job_id
end
|
#num_jobs ⇒ Object
52
53
54
|
# File 'lib/resque/plugins/job_history/history_list.rb', line 52
def num_jobs
redis.llen(job_list_key)
end
|
#paged_jobs(page_num = 1, job_page_size = nil) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/resque/plugins/job_history/history_list.rb', line 32
def paged_jobs(page_num = 1, job_page_size = nil)
job_page_size ||= page_size
job_page_size = job_page_size.to_i
job_page_size = Resque::Plugins::JobHistory::PAGE_SIZE if job_page_size < 1
start = (page_num - 1) * job_page_size
start = 0 if start >= num_jobs || start.negative?
jobs(start, start + job_page_size - 1)
end
|
#remove_job(job_id) ⇒ Object
27
28
29
30
|
# File 'lib/resque/plugins/job_history/history_list.rb', line 27
def remove_job(job_id)
redis.lrem(job_list_key, 0, job_id)
remove_job_data(job_id)
end
|
#total ⇒ Object
56
57
58
|
# File 'lib/resque/plugins/job_history/history_list.rb', line 56
def total
redis.get(total_jobs_key).to_i
end
|