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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b789a390da84dd32ede51b6d8655853e3f20efa55144fe19cf0605d9e5083e62
4
- data.tar.gz: bd263366443698e93572f83a6f0e2b3d747c9e72acd851fbc0aa3f920c413e02
3
+ metadata.gz: 67a4882eeb37fac31a1fd646e0a5a414a3292d7379c243d02b0ede8f9f5f5d89
4
+ data.tar.gz: 5e92f514ea3a561f8e55541a5a7a8b5802909d3ddaf1ea9ec217d2c3c0a6eff9
5
5
  SHA512:
6
- metadata.gz: b902bbdb3d4d676b984a22c2df5d4382960219de7a9a3d639df4fd6f958816ac77a3e2e00e881d7afbc240fd6043eef21f5362885301ccf1c9fb1ae790a21e2f
7
- data.tar.gz: 3dbb3fe818c20be76f6f07f61893014bc881a2f82a7c44139e62642230ff49a2acd0d3e2ba746b4bcdf1834fed0b5cb1ebcbb6ea3431b9fe46ffc29d6956200b
6
+ metadata.gz: d8183e8becaf288a52dec2757b16632fe57c0c05d2f98c3edd9bb13cf732744498c309b0edf6598006fd0914214ae6cf098b965ad64887763524c23616d2ea74
7
+ data.tar.gz: 81650de01fdd02fbb4fcf81b112dc5cfefd4291a439ac8c5aab5faf424c5780b57845c3fe8f69992ed419638289ef0b4f5cab0e6a830d34ba04af160c21139e3
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Delayed
4
- VERSION = "2.1.0"
4
+ VERSION = "2.1.1"
5
5
  end
@@ -209,38 +209,38 @@ class Worker
209
209
  end
210
210
 
211
211
  def perform(job)
212
- count = 1
213
- raise Delayed::Backend::JobExpired, "job expired at #{job.expires_at}" if job.expired?
214
- self.class.lifecycle.run_callbacks(:perform, self, job) do
215
- set_process_name("run:#{Settings.worker_procname_prefix}#{job.id}:#{job.name}")
216
- logger.info("Processing #{log_job(job, :long)}")
217
- runtime = Benchmark.realtime do
218
- if job.batch?
219
- # each job in the batch will have perform called on it, so we don't
220
- # need a timeout around this
221
- count = perform_batch(job)
222
- else
223
- job.invoke_job
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.destroy
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
@@ -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(:last_error= => nil, attempts: 1, reschedule: nil)
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(:last_error= => nil, attempts: 0, reschedule: nil, expired?: false)
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.0
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-07 00:00:00.000000000 Z
12
+ date: 2020-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord