resque-job_history 0.0.16 → 0.0.21

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
  SHA256:
3
- metadata.gz: 7d86950b6a60c676750855dfeeffb782760ff7917450c15cb2b7d3f3346ec17d
4
- data.tar.gz: ad7976566b66d71ff660df3698f3d584d00d48a1bef9f61044ce996331dbf0c8
3
+ metadata.gz: 272a762705e9396cae975b8113183ae579557cf0e77412b6f4c1cb609ff0ff96
4
+ data.tar.gz: c9e0df1f067302a22ee086413f9fa57ae7a56f84cef52d29c27e5dc372336112
5
5
  SHA512:
6
- metadata.gz: f0b931b266f54794b252e174f639f9bda5a27bf3db59e5f8af36a86803cf29332e52465b0551fba2c9934eecbc5b0df2a1ca4663478961634767e319a93f026d
7
- data.tar.gz: '08f87c20c98ebedd24572452c33aa4c8268dc7298bfb87d74bb0bb3bd5043140ac6b1851bbdd629ee3108c3373147cfae0c35c4ae47fcfb7de2f890cb7f786e6'
6
+ metadata.gz: c5cb6a16f6808621408467ed6658822394c1b0eb395589dad5d41657747877b032dc17a12efea5915b8d4ea046b3d95c1af03db36d14b847a33b2b442b95dbe2
7
+ data.tar.gz: df26c5d144fd44da9f331399cd57e71fc9e0972fee60d7c304a5ed5a08eb2fa6599814870f1027d4263839c16620ee222358e6d1995c4e4c1c5f311f443c2332
@@ -10,7 +10,7 @@ module Resque
10
10
  module JobHistory
11
11
  extend ActiveSupport::Concern
12
12
 
13
- # Redis mapp:
13
+ # Redis map:
14
14
  # job_history - a set of all of the class names of all jobs
15
15
  # job_history..linear_jobs - a list of the IDs for all jobs that have run in the order
16
16
  # they were started.
@@ -51,8 +51,8 @@ module Resque
51
51
  end
52
52
 
53
53
  def around_perform_job_history(*args)
54
- running_job = Resque::Plugins::JobHistory::Job.new(active_job_class_name(*args),
55
- SecureRandom.uuid)
54
+ start_time = Time.now
55
+ running_job = Resque::Plugins::JobHistory::Job.new(active_job_class_name(*args), SecureRandom.uuid)
56
56
  self.most_recent_job = running_job
57
57
 
58
58
  begin
@@ -60,12 +60,12 @@ module Resque
60
60
 
61
61
  yield if block_given?
62
62
 
63
- running_job.finish
63
+ running_job.finish(start_time, *args)
64
64
  rescue StandardError => exception
65
- running_job.failed exception
65
+ running_job.failed exception, start_time, *args
66
66
  raise
67
67
  ensure
68
- running_job.cancel unless running_job.finished? || running_job.error
68
+ running_job.cancel(" Job did not signal completion on finish.", start_time, *args) unless running_job.finished? || running_job.error
69
69
  self.most_recent_job = nil
70
70
  end
71
71
  end
@@ -100,18 +100,9 @@ module Resque
100
100
 
101
101
  private
102
102
 
103
- def job_class_has_history?(*args)
104
- if Object.const_defined?("ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper") &&
105
- self >= ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper
106
- args[-1]["job_class"].constantize.included_modules.include? Resque::Plugins::JobHistory
107
- else
108
- true
109
- end
110
- end
111
-
112
103
  def active_job_class_name(*args)
113
104
  if Object.const_defined?("ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper") &&
114
- self >= ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper
105
+ self >= "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper".constantize
115
106
  args[-1]["job_class"]
116
107
  else
117
108
  name
@@ -120,7 +111,7 @@ module Resque
120
111
 
121
112
  def active_job_args(*args)
122
113
  if Object.const_defined?("ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper") &&
123
- self >= ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper
114
+ self >= "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper".constantize
124
115
  args[-1]["arguments"]
125
116
  else
126
117
  args
@@ -145,8 +136,7 @@ module Resque
145
136
  end
146
137
 
147
138
  if Object.const_defined?("ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper")
148
- unless ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper.included_modules.
149
- include? Resque::Plugins::JobHistory
150
- ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper.include Resque::Plugins::JobHistory
139
+ unless "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper".constantize.included_modules.include? Resque::Plugins::JobHistory
140
+ "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper".constantize.include Resque::Plugins::JobHistory
151
141
  end
152
142
  end
@@ -48,6 +48,8 @@ module Resque
48
48
  purge_class class_name
49
49
  end
50
50
 
51
+ purge_linear_history
52
+
51
53
  del_key(Resque::Plugins::JobHistory::HistoryDetails.job_history_key, "Purging job_history_key")
52
54
 
53
55
  redis.keys("*").each do |key|
@@ -68,8 +68,7 @@ module Resque
68
68
  end
69
69
 
70
70
  def linear_jobs
71
- @linear_list ||= HistoryList.new("", "linear",
72
- Resque::Plugins::JobHistory::HistoryDetails.max_linear_jobs)
71
+ @linear_list ||= HistoryList.new("", "linear", Resque::Plugins::JobHistory::HistoryDetails.max_linear_jobs)
73
72
  end
74
73
 
75
74
  def max_concurrent_jobs
@@ -110,9 +109,8 @@ module Resque
110
109
  running_jobs.jobs.each do |job|
111
110
  job_start = job.start_time
112
111
 
113
- if job_start.blank? || job_start.to_time < too_old_time
114
- job.start(*job.args) if job_start.blank?
115
- job.cancel
112
+ if job_start.present? && job_start.to_time < too_old_time
113
+ job.cancel " Job timed out."
116
114
  end
117
115
  end
118
116
  end
@@ -86,11 +86,13 @@ module Resque
86
86
  end
87
87
 
88
88
  def delete_old_jobs(job_count)
89
- while job_count > max_jobs
90
- job_id = redis.rpop(job_list_key)
89
+ while num_jobs > max_jobs
90
+ job_id = redis.rpop(job_list_key)
91
+ job_class_name = job_class(job_id)
92
+
91
93
  remove_job_data(job_id)
92
94
 
93
- Resque::Plugins::JobHistory::Job.new(job_class(job_id), job_id).safe_purge
95
+ Resque::Plugins::JobHistory::Job.new(job_class_name, job_id).safe_purge
94
96
 
95
97
  job_count -= 1
96
98
  end
@@ -33,7 +33,7 @@ module Resque
33
33
  end
34
34
 
35
35
  def duration
36
- (end_time || Time.now) - start_time
36
+ (end_time || Time.now) - (start_time || Time.now)
37
37
  end
38
38
 
39
39
  def end_time
@@ -44,24 +44,39 @@ module Resque
44
44
  decode_args(stored_values[:args])
45
45
  end
46
46
 
47
+ def uncompressed_args
48
+ return args if described_class.blank? || args.blank?
49
+ return args unless described_class.singleton_class.included_modules.map(&:name).include?("Resque::Plugins::Compressible")
50
+ return args unless described_class.compressed?(args)
51
+
52
+ described_class.uncompressed_args(args.first[:payload] || args.first["payload"])
53
+ end
54
+
47
55
  def error
48
56
  stored_values[:error]
49
57
  end
50
58
 
51
59
  def start(*args)
60
+ record_job_start(Time.now.utc.to_s, *args)
61
+
52
62
  num_jobs = running_jobs.add_job(job_id, class_name)
53
63
  linear_jobs.add_job(job_id, class_name) unless class_exclude_from_linear_history
54
64
 
55
- record_job_start(*args)
56
65
  record_num_jobs(num_jobs)
57
66
 
58
67
  self
59
68
  end
60
69
 
61
- def finish
62
- redis.hset(job_key, "end_time", Time.now.utc.to_s)
70
+ def finish(start_time = nil, *args)
71
+ if start_time.present?
72
+ record_job_start(start_time, *args)
73
+ end
74
+
75
+ if redis.exists(job_key)
76
+ redis.hset(job_key, "end_time", Time.now.utc.to_s)
77
+ finished_jobs.add_job(job_id, class_name)
78
+ end
63
79
 
64
- finished_jobs.add_job(job_id, class_name)
65
80
  running_jobs.remove_job(job_id)
66
81
 
67
82
  reset
@@ -69,18 +84,34 @@ module Resque
69
84
  self
70
85
  end
71
86
 
72
- def failed(exception)
73
- redis.hset(job_key, "error", exception_message(exception))
87
+ def failed(exception, start_time = nil, *args)
88
+ if start_time.present?
89
+ record_job_start(start_time, *args)
90
+ end
91
+
92
+ redis.hset(job_key, "error", exception_message(exception)) if redis.exists(job_key)
74
93
  redis.incr(total_failed_key)
75
94
 
76
95
  finish
77
96
  end
78
97
 
79
- def cancel
80
- redis.hset(job_key,
81
- "error",
82
- "Unknown - Job failed to signal ending after the configured purge time or "\
83
- "was canceled manually.")
98
+ def abort
99
+ running_jobs.remove_job(job_id)
100
+
101
+ reset
102
+ end
103
+
104
+ def cancel(caller_message = nil, start_time = nil, *args)
105
+ if start_time.present?
106
+ record_job_start(start_time, *args)
107
+ end
108
+
109
+ if redis.exists(job_key)
110
+ redis.hset(job_key,
111
+ "error",
112
+ "Unknown - Job failed to signal ending after the configured purge time or was canceled manually.#{caller_message}")
113
+ end
114
+
84
115
  redis.incr(total_failed_key)
85
116
 
86
117
  finish
@@ -102,7 +133,7 @@ module Resque
102
133
 
103
134
  def purge
104
135
  # To keep the counts honest...
105
- cancel unless finished?
136
+ abort unless finished?
106
137
 
107
138
  remove_from_job_lists
108
139
 
@@ -127,19 +158,15 @@ module Resque
127
158
  linear_jobs.remove_job(job_id)
128
159
  end
129
160
 
130
- def record_job_start(*args)
131
- redis.hset(job_key, "start_time", Time.now.utc.to_s)
161
+ def record_job_start(start_time, *args)
162
+ redis.hset(job_key, "start_time", start_time)
132
163
  redis.hset(job_key, "args", encode_args(*args))
133
164
 
134
165
  reset
135
166
  end
136
167
 
137
168
  def stored_values
138
- unless @stored_values
139
- @stored_values = redis.hgetall(job_key).with_indifferent_access
140
- end
141
-
142
- @stored_values
169
+ @stored_values ||= redis.hgetall(job_key).with_indifferent_access
143
170
  end
144
171
 
145
172
  def encode_args(*args)
@@ -39,7 +39,7 @@
39
39
  <% end %>
40
40
  </td>
41
41
  <td>
42
- <pre><code><%= "".html_safe + job_details.args.to_yaml %></code></pre>
42
+ <pre><code><%= "".html_safe + job_details.uncompressed_args.to_yaml %></code></pre>
43
43
  </td>
44
44
  <td>
45
45
  <%= job_details.error %>
@@ -26,7 +26,7 @@
26
26
  <td>
27
27
  <% if class_info.last_run %>
28
28
  <% if class_info.last_run.finished? %>
29
- <%= distance_of_time_in_words(class_info.last_run.start_time, class_info.last_run.end_time) %>
29
+ <%= distance_of_time_in_words((class_info.last_run.start_time || Time.now), (class_info.last_run.end_time || Time.now)) %>
30
30
  (<%= class_info.last_run.end_time %>)
31
31
  <% else %>
32
32
  Still running...
@@ -49,7 +49,7 @@
49
49
  Params
50
50
  </td>
51
51
  <td>
52
- <pre><code><%= "".html_safe + job_details.args.to_yaml %></code></pre>
52
+ <pre><code><%= "".html_safe + job_details.uncompressed_args.to_yaml %></code></pre>
53
53
  </td>
54
54
  </tr>
55
55
  <% unless job_details.succeeded? %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque-job_history
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - RealNobody
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-11 00:00:00.000000000 Z
11
+ date: 2020-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resque
@@ -109,21 +109,21 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: rspec-rails
112
+ name: cornucopia
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 3.6.0
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 3.6.0
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: gem-release
126
+ name: faker
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -137,7 +137,7 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: simplecov
140
+ name: gem-release
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - ">="
@@ -151,7 +151,7 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: cornucopia
154
+ name: haml-lint
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
@@ -165,7 +165,7 @@ dependencies:
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
- name: rubocop
168
+ name: rack-test
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - ">="
@@ -179,7 +179,7 @@ dependencies:
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
- name: haml-lint
182
+ name: resque-compressible
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - ">="
@@ -193,7 +193,21 @@ dependencies:
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  - !ruby/object:Gem::Dependency
196
- name: timecop
196
+ name: rspec-rails
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: 3.6.0
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: 3.6.0
209
+ - !ruby/object:Gem::Dependency
210
+ name: rubocop
197
211
  requirement: !ruby/object:Gem::Requirement
198
212
  requirements:
199
213
  - - ">="
@@ -207,7 +221,7 @@ dependencies:
207
221
  - !ruby/object:Gem::Version
208
222
  version: '0'
209
223
  - !ruby/object:Gem::Dependency
210
- name: faker
224
+ name: simplecov
211
225
  requirement: !ruby/object:Gem::Requirement
212
226
  requirements:
213
227
  - - ">="
@@ -221,7 +235,7 @@ dependencies:
221
235
  - !ruby/object:Gem::Version
222
236
  version: '0'
223
237
  - !ruby/object:Gem::Dependency
224
- name: rack-test
238
+ name: timecop
225
239
  requirement: !ruby/object:Gem::Requirement
226
240
  requirements:
227
241
  - - ">="
@@ -266,7 +280,7 @@ files:
266
280
  - lib/resque/server/views/linear_history.erb
267
281
  - lib/resque/server/views/search_results.erb
268
282
  - lib/tasks/resque-job_history_tasks.rake
269
- homepage: https://github.com/RealNobody
283
+ homepage: https://github.com/RealNobody/resque-job_history
270
284
  licenses:
271
285
  - MIT
272
286
  metadata: {}
@@ -285,8 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
285
299
  - !ruby/object:Gem::Version
286
300
  version: '0'
287
301
  requirements: []
288
- rubyforge_project:
289
- rubygems_version: 2.7.6
302
+ rubygems_version: 3.0.3
290
303
  signing_key:
291
304
  specification_version: 4
292
305
  summary: Keeps a history of run jobs by job.