inst-jobs 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/delayed/version.rb +1 -1
- data/lib/delayed/worker.rb +30 -30
- data/spec/delayed/worker_spec.rb +11 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67a4882eeb37fac31a1fd646e0a5a414a3292d7379c243d02b0ede8f9f5f5d89
|
4
|
+
data.tar.gz: 5e92f514ea3a561f8e55541a5a7a8b5802909d3ddaf1ea9ec217d2c3c0a6eff9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8183e8becaf288a52dec2757b16632fe57c0c05d2f98c3edd9bb13cf732744498c309b0edf6598006fd0914214ae6cf098b965ad64887763524c23616d2ea74
|
7
|
+
data.tar.gz: 81650de01fdd02fbb4fcf81b112dc5cfefd4291a439ac8c5aab5faf424c5780b57845c3fe8f69992ed419638289ef0b4f5cab0e6a830d34ba04af160c21139e3
|
data/lib/delayed/version.rb
CHANGED
data/lib/delayed/worker.rb
CHANGED
@@ -209,38 +209,38 @@ class Worker
|
|
209
209
|
end
|
210
210
|
|
211
211
|
def perform(job)
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
212
|
+
begin
|
213
|
+
count = 1
|
214
|
+
raise Delayed::Backend::JobExpired, "job expired at #{job.expires_at}" if job.expired?
|
215
|
+
self.class.lifecycle.run_callbacks(:perform, self, job) do
|
216
|
+
set_process_name("run:#{Settings.worker_procname_prefix}#{job.id}:#{job.name}")
|
217
|
+
logger.info("Processing #{log_job(job, :long)}")
|
218
|
+
runtime = Benchmark.realtime do
|
219
|
+
if job.batch?
|
220
|
+
# each job in the batch will have perform called on it, so we don't
|
221
|
+
# need a timeout around this
|
222
|
+
count = perform_batch(job)
|
223
|
+
else
|
224
|
+
job.invoke_job
|
225
|
+
end
|
226
|
+
job.destroy
|
224
227
|
end
|
225
|
-
job
|
228
|
+
logger.info("Completed #{log_job(job)} #{"%.0fms" % (runtime * 1000)}")
|
229
|
+
end
|
230
|
+
rescue ::Delayed::RetriableError => re
|
231
|
+
can_retry = job.attempts + 1 < job.inferred_max_attempts
|
232
|
+
callback_type = can_retry ? :retry : :error
|
233
|
+
self.class.lifecycle.run_callbacks(callback_type, self, job, re) do
|
234
|
+
handle_failed_job(job, re)
|
235
|
+
end
|
236
|
+
rescue SystemExit => se
|
237
|
+
# There wasn't really a failure here so no callbacks and whatnot needed,
|
238
|
+
# still reschedule the job though.
|
239
|
+
job.reschedule(se)
|
240
|
+
rescue Exception => e
|
241
|
+
self.class.lifecycle.run_callbacks(:error, self, job, e) do
|
242
|
+
handle_failed_job(job, e)
|
226
243
|
end
|
227
|
-
logger.info("Completed #{log_job(job)} #{"%.0fms" % (runtime * 1000)}")
|
228
|
-
end
|
229
|
-
count
|
230
|
-
rescue ::Delayed::RetriableError => re
|
231
|
-
can_retry = job.attempts + 1 < job.inferred_max_attempts
|
232
|
-
callback_type = can_retry ? :retry : :error
|
233
|
-
self.class.lifecycle.run_callbacks(callback_type, self, job, re) do
|
234
|
-
handle_failed_job(job, re)
|
235
|
-
end
|
236
|
-
rescue SystemExit => se
|
237
|
-
# There wasn't really a failure here so no callbacks and whatnot needed,
|
238
|
-
# still reschedule the job though.
|
239
|
-
job.reschedule(se)
|
240
|
-
count
|
241
|
-
rescue Exception => e
|
242
|
-
self.class.lifecycle.run_callbacks(:error, self, job, e) do
|
243
|
-
handle_failed_job(job, e)
|
244
244
|
end
|
245
245
|
count
|
246
246
|
end
|
data/spec/delayed/worker_spec.rb
CHANGED
@@ -6,6 +6,11 @@ describe Delayed::Worker do
|
|
6
6
|
let(:worker_config) { {
|
7
7
|
queue: "test", min_priority: 1, max_priority: 2, stuff: "stuff",
|
8
8
|
}.freeze }
|
9
|
+
let(:job_attrs) { {
|
10
|
+
id: 42, name: "testjob", full_name: "testfullname", :last_error= => nil,
|
11
|
+
attempts: 1, reschedule: nil, :expired? => false,
|
12
|
+
payload_object: {}, priority: 25
|
13
|
+
}.freeze }
|
9
14
|
subject { described_class.new(worker_config.dup) }
|
10
15
|
|
11
16
|
after { Delayed::Worker.lifecycle.reset! }
|
@@ -14,9 +19,10 @@ describe Delayed::Worker do
|
|
14
19
|
it "fires off an error callback when a job raises an exception" do
|
15
20
|
fired = false
|
16
21
|
Delayed::Worker.lifecycle.before(:error) {|worker, exception| fired = true}
|
17
|
-
job = double(
|
18
|
-
subject.perform(job)
|
22
|
+
job = double(job_attrs)
|
23
|
+
output_count = subject.perform(job)
|
19
24
|
expect(fired).to be_truthy
|
25
|
+
expect(output_count).to eq(1)
|
20
26
|
end
|
21
27
|
|
22
28
|
it "uses the retry callback for a retriable exception" do
|
@@ -27,9 +33,10 @@ describe Delayed::Worker do
|
|
27
33
|
expect(job).to receive(:invoke_job) do
|
28
34
|
raise Delayed::RetriableError, "that's all this job does"
|
29
35
|
end
|
30
|
-
subject.perform(job)
|
36
|
+
output_count = subject.perform(job)
|
31
37
|
expect(error_fired).to be_falsey
|
32
38
|
expect(retry_fired).to be_truthy
|
39
|
+
expect(output_count).to eq(1)
|
33
40
|
end
|
34
41
|
|
35
42
|
it "reloads" do
|
@@ -48,7 +55,7 @@ describe Delayed::Worker do
|
|
48
55
|
expect(ActionDispatch::Reloader).to receive(:prepare!).once
|
49
56
|
expect(ActionDispatch::Reloader).to receive(:cleanup!).once
|
50
57
|
end
|
51
|
-
job = double(
|
58
|
+
job = double(job_attrs)
|
52
59
|
subject.perform(job)
|
53
60
|
end
|
54
61
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inst-jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Luetke
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2020-12-
|
12
|
+
date: 2020-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|