resque-job_history 0.0.17 → 0.0.22

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: b43c1dc7fc2ffd02571c60c0f50d4e7426bfd182e44dda1bb76175c2178b0606
4
- data.tar.gz: 84edfdefea39d88c6ef623587d72ed0c97bf51b712d232e193cfe64c07da6766
3
+ metadata.gz: 6d328ea1b14c7876088234d1c4d3640423ab2f8059006eaadbf908ca73275afa
4
+ data.tar.gz: d59d30e5ddc0d79bb6812b17f5f5236aa8cda1ea973c699ce32576718257bbcf
5
5
  SHA512:
6
- metadata.gz: a2cf03c484c94b3a3fbe3374bde9e9d159f859a2959962b2a280c0c3d2d1746a30d4eda389f6e75c9001513dbe9d5bcc01240791cc5b023265a8d8863c61b2ba
7
- data.tar.gz: e5077bab52fadd868706ceaa9fc766a57abc73a241627fb1be0537434b11192caf7e1cb97f14d2192a98063f57736b78d94cfaa9825238ba95741cbb8df44e40
6
+ metadata.gz: f0ae0984ef34a9a40519d68cbc9e0338b414df97b52f130dec1e3c5a2e547bccdd84330f2966cd8518c4731bdba3684ce408034cadebb9b9ca96f523649d2809
7
+ data.tar.gz: da4a3ce71e67a2aaeca3784fb29accf6075aeb70b2c087d4790b3713997626aa14d9ade0a02efe1152f58a4a01901906ad701f5598a199e037076cbe4df1a267
@@ -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,15 @@ 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
+ if running_job.present? && !running_job.finished? && !running_job.error
69
+ running_job.cancel(" Job did not signal completion on finish.", start_time, *args)
70
+ end
71
+
69
72
  self.most_recent_job = nil
70
73
  end
71
74
  end
@@ -100,18 +103,9 @@ module Resque
100
103
 
101
104
  private
102
105
 
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
106
  def active_job_class_name(*args)
113
107
  if Object.const_defined?("ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper") &&
114
- self >= ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper
108
+ self >= "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper".constantize
115
109
  args[-1]["job_class"]
116
110
  else
117
111
  name
@@ -120,7 +114,7 @@ module Resque
120
114
 
121
115
  def active_job_args(*args)
122
116
  if Object.const_defined?("ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper") &&
123
- self >= ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper
117
+ self >= "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper".constantize
124
118
  args[-1]["arguments"]
125
119
  else
126
120
  args
@@ -145,8 +139,7 @@ module Resque
145
139
  end
146
140
 
147
141
  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
142
+ unless "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper".constantize.included_modules.include? Resque::Plugins::JobHistory
143
+ "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper".constantize.include Resque::Plugins::JobHistory
151
144
  end
152
145
  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
@@ -28,12 +28,16 @@ module Resque
28
28
  stored_values[:end_time].present?
29
29
  end
30
30
 
31
+ def blank?
32
+ !redis.exists job_key
33
+ end
34
+
31
35
  def succeeded?
32
36
  error.blank?
33
37
  end
34
38
 
35
39
  def duration
36
- (end_time || Time.now) - start_time
40
+ (end_time || Time.now) - (start_time || Time.now)
37
41
  end
38
42
 
39
43
  def end_time
@@ -44,24 +48,39 @@ module Resque
44
48
  decode_args(stored_values[:args])
45
49
  end
46
50
 
51
+ def uncompressed_args
52
+ return args if described_class.blank? || args.blank?
53
+ return args unless described_class.singleton_class.included_modules.map(&:name).include?("Resque::Plugins::Compressible")
54
+ return args unless described_class.compressed?(args)
55
+
56
+ described_class.uncompressed_args(args.first[:payload] || args.first["payload"])
57
+ end
58
+
47
59
  def error
48
60
  stored_values[:error]
49
61
  end
50
62
 
51
63
  def start(*args)
64
+ record_job_start(Time.now.utc.to_s, *args)
65
+
52
66
  num_jobs = running_jobs.add_job(job_id, class_name)
53
67
  linear_jobs.add_job(job_id, class_name) unless class_exclude_from_linear_history
54
68
 
55
- record_job_start(*args)
56
69
  record_num_jobs(num_jobs)
57
70
 
58
71
  self
59
72
  end
60
73
 
61
- def finish
62
- redis.hset(job_key, "end_time", Time.now.utc.to_s)
74
+ def finish(start_time = nil, *args)
75
+ if start_time.present?
76
+ record_job_start(start_time, *args)
77
+ end
78
+
79
+ if present?
80
+ redis.hset(job_key, "end_time", Time.now.utc.to_s)
81
+ finished_jobs.add_job(job_id, class_name)
82
+ end
63
83
 
64
- finished_jobs.add_job(job_id, class_name)
65
84
  running_jobs.remove_job(job_id)
66
85
 
67
86
  reset
@@ -69,18 +88,34 @@ module Resque
69
88
  self
70
89
  end
71
90
 
72
- def failed(exception)
73
- redis.hset(job_key, "error", exception_message(exception))
91
+ def failed(exception, start_time = nil, *args)
92
+ if start_time.present?
93
+ record_job_start(start_time, *args)
94
+ end
95
+
96
+ redis.hset(job_key, "error", exception_message(exception)) if present?
74
97
  redis.incr(total_failed_key)
75
98
 
76
99
  finish
77
100
  end
78
101
 
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.")
102
+ def abort
103
+ running_jobs.remove_job(job_id)
104
+
105
+ reset
106
+ end
107
+
108
+ def cancel(caller_message = nil, start_time = nil, *args)
109
+ if start_time.present?
110
+ record_job_start(start_time, *args)
111
+ end
112
+
113
+ if present?
114
+ redis.hset(job_key,
115
+ "error",
116
+ "Unknown - Job failed to signal ending after the configured purge time or was canceled manually.#{caller_message}")
117
+ end
118
+
84
119
  redis.incr(total_failed_key)
85
120
 
86
121
  finish
@@ -102,7 +137,7 @@ module Resque
102
137
 
103
138
  def purge
104
139
  # To keep the counts honest...
105
- cancel unless finished?
140
+ abort unless finished?
106
141
 
107
142
  remove_from_job_lists
108
143
 
@@ -127,19 +162,15 @@ module Resque
127
162
  linear_jobs.remove_job(job_id)
128
163
  end
129
164
 
130
- def record_job_start(*args)
131
- redis.hset(job_key, "start_time", Time.now.utc.to_s)
165
+ def record_job_start(start_time, *args)
166
+ redis.hset(job_key, "start_time", start_time)
132
167
  redis.hset(job_key, "args", encode_args(*args))
133
168
 
134
169
  reset
135
170
  end
136
171
 
137
172
  def stored_values
138
- unless @stored_values
139
- @stored_values = redis.hgetall(job_key).with_indifferent_access
140
- end
141
-
142
- @stored_values
173
+ @stored_values ||= redis.hgetall(job_key).with_indifferent_access
143
174
  end
144
175
 
145
176
  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 %>
@@ -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.17
4
+ version: 0.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - RealNobody
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-16 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: {}