resque-job_history 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e5bff0c1faf1c5b7320a96c5b085e8baf35b712
4
- data.tar.gz: 4ada6c6a3fc999730bba715e840285e1e6b9dfd1
3
+ metadata.gz: 0c3f478df1a3604bb27c14414e3ed7ffbfc34dde
4
+ data.tar.gz: 9b0d78e32b57b098cd8150747372df8bbf203600
5
5
  SHA512:
6
- metadata.gz: 7510483ab78cdd4571de32e388235a654d7c1afa71eac5dc28f951eca1c34401b6dcd84b6715907c24346d7579146f198a7e3b885952733d592294d68f822c1a
7
- data.tar.gz: e75083c6ae8aaf7141ad8541127bd44368876c7e797b0b930101f5d5da0243f8f26e611a31206f341eb0c3ee4feecdf09464137ec83db213d5e1bfffa585c41f
6
+ metadata.gz: 1fcb4e9aa99d234359507f689cc329f311b5c98f3f2d61864f37ae40dd2aa616b79ccf20b36421839a71fd8412acdb7a204511c7cf44098f47aef44edb6f9526
7
+ data.tar.gz: f610d895c93dfeeb2eeb29e71c2c96a47e414a768da3606bfd39c5f3e062f81b84a6c07ab8411523ccb2d6a689eb8a6e7aba2b1be9a211a024be6463ef68ff3f
@@ -80,10 +80,30 @@ module Resque
80
80
  redis.get(total_failed_key).to_i
81
81
  end
82
82
 
83
+ def num_running_jobs
84
+ running_jobs.num_jobs
85
+ end
86
+
87
+ def num_finished_jobs
88
+ finished_jobs.num_jobs
89
+ end
90
+
91
+ def total_run_jobs
92
+ running_jobs.total
93
+ end
94
+
95
+ def total_finished_jobs
96
+ finished_jobs.total
97
+ end
98
+
83
99
  def class_name_valid?
84
100
  described_class.present?
85
101
  end
86
102
 
103
+ def last_run
104
+ running_jobs.latest_job || finished_jobs.latest_job
105
+ end
106
+
87
107
  def clean_old_running_jobs
88
108
  too_old_time = class_purge_age.ago
89
109
 
@@ -104,6 +124,8 @@ module Resque
104
124
  private
105
125
 
106
126
  def described_class
127
+ return if class_name.blank?
128
+
107
129
  class_name.constantize
108
130
  rescue StandardError
109
131
  nil
@@ -113,6 +135,10 @@ module Resque
113
135
  described_class.try(:purge_age) || 24.hours
114
136
  end
115
137
 
138
+ def class_exclude_from_linear_history
139
+ described_class.try(:exclude_from_linear_history) || false
140
+ end
141
+
116
142
  def class_history_len
117
143
  hist_len = described_class.try(:job_history_len) || MAX_JOB_HISTORY
118
144
  hist_len.negative? ? 0 : hist_len
@@ -27,7 +27,7 @@ module Resque
27
27
  end
28
28
 
29
29
  def succeeded?
30
- finished? && error.blank?
30
+ error.blank?
31
31
  end
32
32
 
33
33
  def duration
@@ -48,7 +48,7 @@ module Resque
48
48
 
49
49
  def start(*args)
50
50
  num_jobs = running_jobs.add_job(job_id, class_name)
51
- linear_jobs.add_job(job_id, class_name)
51
+ linear_jobs.add_job(job_id, class_name) unless class_exclude_from_linear_history
52
52
 
53
53
  record_job_start(*args)
54
54
  record_num_jobs(num_jobs)
@@ -105,14 +105,14 @@ module Resque
105
105
  reset
106
106
  end
107
107
 
108
+ private
109
+
108
110
  def remove_from_job_lists
109
111
  running_jobs.remove_job(job_id)
110
112
  finished_jobs.remove_job(job_id)
111
113
  linear_jobs.remove_job(job_id)
112
114
  end
113
115
 
114
- private
115
-
116
116
  def record_job_start(*args)
117
117
  redis.hset(job_key, "start_time", Time.now.utc.to_s)
118
118
  redis.hset(job_key, "args", encode_args(*args))
@@ -37,58 +37,42 @@ module Resque
37
37
  redis.smembers(Resque::Plugins::JobHistory::HistoryDetails.job_history_key)
38
38
  end
39
39
 
40
- def job_class_summary(class_name)
41
- history = Resque::Plugins::JobHistory::HistoryDetails.new(class_name)
42
-
43
- running_list = history.running_jobs
44
- finished_list = history.finished_jobs
45
-
46
- class_summary_hash(class_name, finished_list, running_list)
40
+ def job_details(class_name)
41
+ Resque::Plugins::JobHistory::HistoryDetails.new(class_name)
47
42
  end
48
43
 
49
44
  private
50
45
 
51
- def latest_job(running_list, finished_list)
52
- running_list.latest_job || finished_list.latest_job
53
- end
54
-
55
46
  def sorted_job_summaries(sort_key)
56
- job_classes.map { |class_name| job_class_summary(class_name) }.sort_by do |job_summary|
57
- summary_sort_value(job_summary, sort_key)
47
+ job_classes.map { |class_name| job_details(class_name) }.sort_by do |job_details|
48
+ summary_sort_value(job_details, sort_key)
58
49
  end
59
50
  end
60
51
 
61
- def summary_sort_value(job_summary, sort_key)
52
+ def summary_sort_value(job_details, sort_key)
62
53
  case sort_key.to_sym
63
54
  when :class_name,
64
- :running_jobs,
65
- :finished_jobs,
55
+ :num_running_jobs,
56
+ :num_finished_jobs,
66
57
  :total_finished_jobs,
67
58
  :total_run_jobs,
68
- :max_running_jobs
69
- job_summary[sort_key.to_sym]
59
+ :max_concurrent_jobs
60
+ job_details.public_send sort_key
61
+ else
62
+ last_run_sort_value(job_details.last_run, sort_key)
63
+ end
64
+ end
65
+
66
+ def last_run_sort_value(last_run, sort_key)
67
+ case sort_key.to_sym
70
68
  when :start_time
71
- job_summary[:last_run].start_time
69
+ last_run.start_time || Time.now
72
70
  when :duration
73
- job_summary[:last_run].duration
71
+ last_run.duration
74
72
  when :success
75
- job_summary[:last_run].succeeded? ? 1 : 0
73
+ last_run.succeeded? ? 1 : 0
76
74
  end
77
75
  end
78
-
79
- def class_summary_hash(class_name, finished_list, running_list)
80
- { class_name: class_name,
81
- class_name_valid: running_list.class_name_valid?,
82
- running_jobs: running_list.num_jobs,
83
- finished_jobs: finished_list.num_jobs,
84
- total_run_jobs: running_list.total,
85
- total_finished_jobs: finished_list.total,
86
- max_concurrent_jobs: Resque::Plugins::JobHistory::HistoryDetails.new(class_name).
87
- max_concurrent_jobs,
88
- total_failed_jobs: Resque::Plugins::JobHistory::HistoryDetails.new(class_name).
89
- total_failed_jobs,
90
- last_run: latest_job(running_list, finished_list) }
91
- end
92
76
  end
93
77
  end
94
78
  end
@@ -70,6 +70,10 @@ module Resque
70
70
  @page_size ||= Resque::Plugins::JobHistory::PAGE_SIZE
71
71
  end
72
72
 
73
+ def exclude_from_linear_history
74
+ @exclude_from_linear_history ||= false
75
+ end
76
+
73
77
  def job_history
74
78
  Resque::Plugins::JobHistory::HistoryDetails.new(name)
75
79
  end
@@ -3,7 +3,7 @@
3
3
  module Resque
4
4
  module Plugins
5
5
  module JobHistory
6
- VERSION = "0.0.6"
6
+ VERSION = "0.0.8"
7
7
  end
8
8
  end
9
9
  end
@@ -24,14 +24,20 @@
24
24
  <tr<%= job_details.succeeded? ? "" : " class=\"job_history_error\"" %>>
25
25
  <td>
26
26
  <a href="job_details?class_name=<%= job_details.class_name %>&job_id=<%= job_details.job_id %>">
27
- <%= time_ago_in_words(job_details.start_time) %> ago
28
- (<%= job_details.start_time %>)
27
+ <% if job_details.start_time %>
28
+ <%= time_ago_in_words(job_details.start_time) %> ago
29
+ (<%= job_details.start_time %>)
30
+ <% else %>
31
+ Error - missing start time
32
+ <% end %>
29
33
  </a>
30
34
  </td>
31
35
  <td>
32
- <%= distance_of_time_in_words(job_details.start_time, (job_details.end_time || Time.now)) %>
33
- <% if job_details.finished? %>
34
- (<%= job_details.end_time %>)
36
+ <% if job_details.start_time %>
37
+ <%= distance_of_time_in_words(job_details.start_time, (job_details.end_time || Time.now)) %>
38
+ <% if job_details.finished? %>
39
+ (<%= job_details.end_time %>)
40
+ <% end %>
35
41
  <% end %>
36
42
  </td>
37
43
  <td>
@@ -4,7 +4,7 @@
4
4
 
5
5
  <% job_list = Resque::Plugins::JobHistory::JobList.new %>
6
6
  <% history = Resque::Plugins::JobHistory::HistoryDetails.new(@job_class_name) %>
7
- <% class_info = job_list.job_class_summary(@job_class_name) %>
7
+ <% class_info = job_list.job_details(@job_class_name) %>
8
8
 
9
9
  <p>
10
10
  <a href="<%= u("job history") %>">
@@ -19,7 +19,7 @@
19
19
  Running jobs
20
20
  </td>
21
21
  <td>
22
- <%= class_info[:running_jobs].to_i %>
22
+ <%= class_info.num_running_jobs.to_i %>
23
23
  </td>
24
24
  </tr>
25
25
  <tr>
@@ -27,7 +27,7 @@
27
27
  Total jobs run
28
28
  </td>
29
29
  <td>
30
- <%= class_info[:total_run_jobs].to_i %>
30
+ <%= class_info.total_run_jobs.to_i %>
31
31
  </td>
32
32
  </tr>
33
33
  <tr>
@@ -35,7 +35,7 @@
35
35
  Total jobs finished
36
36
  </td>
37
37
  <td>
38
- <%= class_info[:total_finished_jobs].to_i %>
38
+ <%= class_info.total_finished_jobs.to_i %>
39
39
  </td>
40
40
  </tr>
41
41
  <tr>
@@ -43,7 +43,7 @@
43
43
  Total jobs in history
44
44
  </td>
45
45
  <td>
46
- <%= class_info[:finished_jobs].to_i %>
46
+ <%= class_info.num_finished_jobs.to_i %>
47
47
  </td>
48
48
  </tr>
49
49
  <tr>
@@ -51,7 +51,7 @@
51
51
  Maximum number of consecutive jobs seen
52
52
  </td>
53
53
  <td>
54
- <%= class_info[:max_running_jobs].to_i %>
54
+ <%= class_info.max_concurrent_jobs.to_i %>
55
55
  </td>
56
56
  </tr>
57
57
  <tr>
@@ -59,7 +59,7 @@
59
59
  Is still valid job
60
60
  </td>
61
61
  <td>
62
- <%= class_info[:class_name_valid] %>
62
+ <%= class_info.class_name_valid? %>
63
63
  </td>
64
64
  </tr>
65
65
  </table>
@@ -23,8 +23,12 @@
23
23
  Started
24
24
  </td>
25
25
  <td>
26
- <%= time_ago_in_words(job_details.start_time) %> ago
27
- (<%= job_details.start_time %>)
26
+ <% if job_details.start_time %>
27
+ <%= time_ago_in_words(job_details.start_time) %> ago
28
+ (<%= job_details.start_time %>)
29
+ <% else %>
30
+ Error - missing start time
31
+ <% end %>
28
32
  </td>
29
33
  </tr>
30
34
  <tr>
@@ -32,9 +36,11 @@
32
36
  Duration
33
37
  </td>
34
38
  <td>
35
- <%= distance_of_time_in_words(job_details.start_time, (job_details.end_time || Time.now)) %>
36
- <% if job_details.finished? %>
37
- (<%= job_details.end_time %>)
39
+ <% if job_details.start_time %>
40
+ <%= distance_of_time_in_words(job_details.start_time, (job_details.end_time || Time.now)) %>
41
+ <% if job_details.finished? %>
42
+ (<%= job_details.end_time %>)
43
+ <% end %>
38
44
  <% end %>
39
45
  </td>
40
46
  </tr>
@@ -23,11 +23,11 @@
23
23
  order_param("class_name", @sort_by, @sort_order) }.to_param %>">
24
24
  Class name
25
25
  </a></th>
26
- <th><a href="job%20history?<%= { sort: "running_jobs",
26
+ <th><a href="job%20history?<%= { sort: "num_running_jobs",
27
27
  page_size: @page_size,
28
28
  page_num: @page_num,
29
29
  order: job_list.
30
- order_param("running_jobs", @sort_by, @sort_order) }.to_param %>">
30
+ order_param("num_running_jobs", @sort_by, @sort_order) }.to_param %>">
31
31
  Running
32
32
  </a></th>
33
33
  <th><a href="job%20history?<%= { sort: "total_run_jobs",
@@ -44,11 +44,11 @@
44
44
  order_param("total_finished_jobs", @sort_by, @sort_order) }.to_param %>">
45
45
  Finished
46
46
  </a></th>
47
- <th><a href="job%20history?<%= { sort: "max_running_jobs",
47
+ <th><a href="job%20history?<%= { sort: "max_concurrent_jobs",
48
48
  page_size: @page_size,
49
49
  page_num: @page_num,
50
50
  order: job_list.
51
- order_param("max_running_jobs", @sort_by, @sort_order) }.to_param %>">
51
+ order_param("max_concurrent_jobs", @sort_by, @sort_order) }.to_param %>">
52
52
  Max Running
53
53
  </a></th>
54
54
  <th><a href="job%20history?<%= { sort: "start_time",
@@ -75,42 +75,42 @@
75
75
  </tr>
76
76
 
77
77
  <% job_list.job_summaries(@sort_by, @sort_order, @page_num, @page_size).each do |class_info| %>
78
- <tr<%= class_info[:last_run] && !class_info[:last_run].succeeded? ? " class=\"job_history_error\"" : "" %>>
78
+ <tr<%= class_info.last_run && !class_info.last_run.succeeded? ? " class=\"job_history_error\"" : "" %>>
79
79
  <td>
80
- <a href="job%20history/job_class_details?class_name=<%= class_info[:class_name] %>">
81
- <%= class_info[:class_name] %>
80
+ <a href="job%20history/job_class_details?class_name=<%= class_info.class_name %>">
81
+ <%= class_info.class_name %>
82
82
  </a>
83
83
  </td>
84
84
  <td>
85
- <%= class_info[:running_jobs].to_i %>
85
+ <%= class_info.num_running_jobs.to_i %>
86
86
  </td>
87
87
  <td>
88
- <%= class_info[:total_run_jobs].to_i %>
88
+ <%= class_info.total_run_jobs.to_i %>
89
89
  </td>
90
90
  <td>
91
- <%= class_info[:total_finished_jobs].to_i %>
91
+ <%= class_info.total_finished_jobs.to_i %>
92
92
  </td>
93
93
  <td>
94
- <%= class_info[:max_running_jobs].to_i %>
94
+ <%= class_info.max_concurrent_jobs.to_i %>
95
95
  </td>
96
96
  <td>
97
- <% if class_info[:last_run] && class_info[:last_run].start_time %>
98
- <%= time_ago_in_words(class_info[:last_run].start_time) %> ago
99
- (<%= class_info[:last_run].start_time %>)
97
+ <% if class_info.last_run && class_info.last_run.start_time %>
98
+ <%= time_ago_in_words(class_info.last_run.start_time) %> ago
99
+ (<%= class_info.last_run.start_time %>)
100
100
  <% end %>
101
101
  </td>
102
102
  <td>
103
- <% if class_info[:last_run] %>
104
- <% if class_info[:last_run].finished? %>
105
- <%= distance_of_time_in_words(class_info[:last_run].start_time, class_info[:last_run].end_time) %>
106
- (<%= class_info[:last_run].end_time %>)
103
+ <% if class_info.last_run %>
104
+ <% if class_info.last_run.finished? %>
105
+ <%= distance_of_time_in_words(class_info.last_run.start_time, class_info.last_run.end_time) %>
106
+ (<%= class_info.last_run.end_time %>)
107
107
  <% else %>
108
108
  Still running...
109
109
  <% end %>
110
110
  <% end %>
111
111
  </td>
112
112
  <td>
113
- <% if class_info[:last_run] && !class_info[:last_run].succeeded? %>
113
+ <% if class_info.last_run && !class_info.last_run.succeeded? %>
114
114
  No
115
115
  <% else %>
116
116
  Yes
@@ -34,11 +34,15 @@
34
34
  </a>
35
35
  </td>
36
36
  <td>
37
- <%= time_ago_in_words(job_details.start_time) %> ago
38
- (<%= job_details.start_time %>)
37
+ <% if job_details.start_time %>
38
+ <%= time_ago_in_words(job_details.start_time) %> ago
39
+ (<%= job_details.start_time %>)
40
+ <% else %>
41
+ Error - missing start time
42
+ <% end %>
39
43
  </td>
40
44
  <td>
41
- <%= distance_of_time_in_words(job_details.start_time, (job_details.end_time || Time.now)) %>
45
+ <%# = distance_of_time_in_words(job_details.start_time, (job_details.end_time || Time.now)) %>
42
46
  <% if job_details.finished? %>
43
47
  (<%= job_details.end_time %>)
44
48
  <% end %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-job_history
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - RealNobody