inst-jobs 3.0.13 → 3.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/20220519204546_add_requeued_job_id_to_failed_jobs.rb +7 -0
- data/lib/delayed/backend/active_record.rb +15 -0
- data/lib/delayed/backend/base.rb +8 -2
- data/lib/delayed/lifecycle.rb +2 -1
- data/lib/delayed/server.rb +1 -1
- data/lib/delayed/version.rb +1 -1
- data/lib/delayed/worker.rb +1 -1
- data/spec/active_record_job_spec.rb +23 -0
- data/spec/shared/shared_backend.rb +18 -1
- data/spec/shared/worker.rb +1 -1
- data/spec/spec_helper.rb +3 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95bdbd537405c6325f378bed05570a3149053ba8a2e290893010c590df72ea9a
|
4
|
+
data.tar.gz: 6f0d577f1fba37bb01e3e0a4ec05b600e65ebb77d001e29e38b479f6facde73b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38392cab25180d44f40960ffb15b2dd3241bd739980b9d0962b93020a809497bb1a9022caf7a05f4ba40f4cc3792281f03468946c33a1fc62891dec3b411f7cf
|
7
|
+
data.tar.gz: cbea2ab6e762a876994179ac1c9ffd414ea2ec13905931b2cddb087d816664e8b682ecf8f9406726d8f80a0867b8e44bc1331b6e0e73de3415b4ab31090d1ee9
|
@@ -583,6 +583,21 @@ module Delayed
|
|
583
583
|
def self.cleanup_old_jobs(before_date, batch_size: 10_000)
|
584
584
|
where("failed_at < ?", before_date).in_batches(of: batch_size).delete_all
|
585
585
|
end
|
586
|
+
|
587
|
+
def requeue!
|
588
|
+
attrs = attributes.except("id", "last_error", "locked_at", "failed_at", "locked_by", "original_job_id",
|
589
|
+
"requeued_job_id")
|
590
|
+
self.class.transaction do
|
591
|
+
job = nil
|
592
|
+
Delayed::Worker.lifecycle.run_callbacks(:create, attrs.merge("payload_object" => payload_object)) do
|
593
|
+
job = Job.create(attrs)
|
594
|
+
end
|
595
|
+
self.requeued_job_id = job.id
|
596
|
+
save!
|
597
|
+
JobTracking.job_created(job)
|
598
|
+
job
|
599
|
+
end
|
600
|
+
end
|
586
601
|
end
|
587
602
|
end
|
588
603
|
end
|
data/lib/delayed/backend/base.rb
CHANGED
@@ -86,8 +86,12 @@ module Delayed
|
|
86
86
|
kwargs.merge!(n_strand_options(full_strand_name, num_strands))
|
87
87
|
end
|
88
88
|
|
89
|
+
job = nil
|
90
|
+
|
89
91
|
if singleton
|
90
|
-
|
92
|
+
Delayed::Worker.lifecycle.run_callbacks(:create, kwargs) do
|
93
|
+
job = create(**kwargs)
|
94
|
+
end
|
91
95
|
elsif batches && strand.nil? && run_at.nil?
|
92
96
|
batch_enqueue_args = kwargs.slice(*self.batch_enqueue_args)
|
93
97
|
batches[batch_enqueue_args] << kwargs
|
@@ -95,7 +99,9 @@ module Delayed
|
|
95
99
|
else
|
96
100
|
raise ArgumentError, "on_conflict can only be provided with singleton" if kwargs[:on_conflict]
|
97
101
|
|
98
|
-
|
102
|
+
Delayed::Worker.lifecycle.run_callbacks(:create, kwargs) do
|
103
|
+
job = create(**kwargs)
|
104
|
+
end
|
99
105
|
end
|
100
106
|
|
101
107
|
JobTracking.job_created(job)
|
data/lib/delayed/lifecycle.rb
CHANGED
@@ -5,6 +5,7 @@ module Delayed
|
|
5
5
|
|
6
6
|
class Lifecycle
|
7
7
|
EVENTS = {
|
8
|
+
create: [:args],
|
8
9
|
error: %i[worker job exception],
|
9
10
|
exceptional_exit: %i[worker exception],
|
10
11
|
execute: [:worker],
|
@@ -76,7 +77,7 @@ module Delayed
|
|
76
77
|
def execute(*args, &block)
|
77
78
|
@before.each { |c| c.call(*args) }
|
78
79
|
result = @around.call(*args, &block)
|
79
|
-
@after.each { |c| c.call(*args) }
|
80
|
+
@after.each { |c| c.call(*args, result: result) }
|
80
81
|
result
|
81
82
|
end
|
82
83
|
|
data/lib/delayed/server.rb
CHANGED
@@ -16,7 +16,7 @@ module Delayed
|
|
16
16
|
# Rails will take care of establishing the DB connection for us if there is
|
17
17
|
# an application present
|
18
18
|
if using_active_record? && !ActiveRecord::Base.connected?
|
19
|
-
ActiveRecord::Base.establish_connection(ENV
|
19
|
+
ActiveRecord::Base.establish_connection(ENV.fetch("DATABASE_URL", nil))
|
20
20
|
end
|
21
21
|
|
22
22
|
@allow_update = args.length.positive? && args[0][:update]
|
data/lib/delayed/version.rb
CHANGED
data/lib/delayed/worker.rb
CHANGED
@@ -276,7 +276,7 @@ module Delayed
|
|
276
276
|
# set up the session context information, so that it gets logged with the job log lines
|
277
277
|
# also set up a unique tmpdir, which will get removed at the end of the job.
|
278
278
|
def configure_for_job(job)
|
279
|
-
previous_tmpdir = ENV
|
279
|
+
previous_tmpdir = ENV.fetch("TMPDIR", nil)
|
280
280
|
|
281
281
|
self.class.running_job(job) do
|
282
282
|
dir = Dir.mktmpdir("job-#{job.id}-#{name.gsub(/[^\w.]/, '.')}-")
|
@@ -300,4 +300,27 @@ describe "Delayed::Backed::ActiveRecord::Job" do
|
|
300
300
|
allow(Delayed::Job.connection).to receive(:execute).and_call_original
|
301
301
|
end
|
302
302
|
end
|
303
|
+
|
304
|
+
context "Failed#requeue!" do
|
305
|
+
it "requeues a failed job" do
|
306
|
+
j = create_job(attempts: 1, max_attempts: 1)
|
307
|
+
fj = j.fail!
|
308
|
+
|
309
|
+
lifecycle_args = nil
|
310
|
+
Delayed::Worker.lifecycle.after(:create) do |args|
|
311
|
+
lifecycle_args = args
|
312
|
+
end
|
313
|
+
j2 = fj.requeue!
|
314
|
+
expect(lifecycle_args["payload_object"].class).to eq SimpleJob
|
315
|
+
expect(fj.reload.requeued_job_id).to eq j2.id
|
316
|
+
|
317
|
+
orig_atts = j.attributes.except("id", "locked_at", "locked_by")
|
318
|
+
new_atts = j2.attributes.except("id", "locked_at", "locked_by")
|
319
|
+
expect(orig_atts).to eq(new_atts)
|
320
|
+
|
321
|
+
# ensure the requeued job actually runs even though `attempts` are maxed out
|
322
|
+
# (so it will not be retried after being manually requeued)
|
323
|
+
expect { run_job(j2) }.to change(SimpleJob, :runs).by(1)
|
324
|
+
end
|
325
|
+
end
|
303
326
|
end
|
@@ -35,6 +35,23 @@ shared_examples_for "a backend" do
|
|
35
35
|
expect(Delayed::Job.jobs_count(:current)).to eq(1)
|
36
36
|
end
|
37
37
|
|
38
|
+
it "triggers the lifecycle event around the create" do
|
39
|
+
called = false
|
40
|
+
created_job = nil
|
41
|
+
|
42
|
+
Delayed::Worker.lifecycle.after(:create) do |_, result:|
|
43
|
+
called = true
|
44
|
+
created_job = result
|
45
|
+
end
|
46
|
+
|
47
|
+
job = SimpleJob.new
|
48
|
+
Delayed::Job.enqueue(job)
|
49
|
+
|
50
|
+
expect(called).to be_truthy
|
51
|
+
expect(created_job).to be_kind_of Delayed::Job
|
52
|
+
expect(created_job.tag).to eq "SimpleJob#perform"
|
53
|
+
end
|
54
|
+
|
38
55
|
it "is able to set priority when enqueuing items" do
|
39
56
|
@job = Delayed::Job.enqueue SimpleJob.new, priority: 5
|
40
57
|
expect(@job.priority).to eq(5)
|
@@ -65,7 +82,7 @@ shared_examples_for "a backend" do
|
|
65
82
|
it "works with jobs in modules" do
|
66
83
|
M::ModuleJob.runs = 0
|
67
84
|
job = Delayed::Job.enqueue M::ModuleJob.new
|
68
|
-
expect { job.invoke_job }.to change
|
85
|
+
expect { job.invoke_job }.to change(M::ModuleJob, :runs).from(0).to(1)
|
69
86
|
end
|
70
87
|
|
71
88
|
it "raises an DeserializationError when the job class is totally unknown" do
|
data/spec/shared/worker.rb
CHANGED
@@ -347,7 +347,7 @@ shared_examples_for "Delayed::Worker" do
|
|
347
347
|
|
348
348
|
it "does not run expired jobs" do
|
349
349
|
Delayed::Job.enqueue SimpleJob.new, expires_at: Delayed::Job.db_time_now - 1.day
|
350
|
-
expect { @worker.run }.
|
350
|
+
expect { @worker.run }.not_to change(SimpleJob, :runs)
|
351
351
|
end
|
352
352
|
|
353
353
|
it "reports a permanent failure when an expired job is dequeued" do
|
data/spec/spec_helper.rb
CHANGED
@@ -47,14 +47,14 @@ RSpec::Core::ExampleGroup.include(NoYamlDump)
|
|
47
47
|
|
48
48
|
ENV["TEST_ENV_NUMBER"] ||= "1"
|
49
49
|
ENV["TEST_DB_HOST"] ||= "localhost"
|
50
|
-
ENV["TEST_DB_DATABASE"] ||= "inst-jobs-test-#{ENV
|
50
|
+
ENV["TEST_DB_DATABASE"] ||= "inst-jobs-test-#{ENV.fetch('TEST_ENV_NUMBER', nil)}"
|
51
51
|
|
52
52
|
connection_config = {
|
53
53
|
adapter: :postgresql,
|
54
54
|
host: ENV["TEST_DB_HOST"].presence,
|
55
55
|
encoding: "utf8",
|
56
|
-
username: ENV
|
57
|
-
database: ENV
|
56
|
+
username: ENV.fetch("TEST_DB_USERNAME", nil),
|
57
|
+
database: ENV.fetch("TEST_DB_DATABASE", nil),
|
58
58
|
min_messages: "notice",
|
59
59
|
# Ensure the pool is big enough the deadlock tests don't get starved for connections by rails instead
|
60
60
|
pool: 20
|
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: 3.
|
4
|
+
version: 3.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Cutrer
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-05-25 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -460,6 +460,7 @@ files:
|
|
460
460
|
- db/migrate/20220128084900_update_delete_trigger_for_singleton_unique_constraint_change.rb
|
461
461
|
- db/migrate/20220203063200_remove_old_singleton_index.rb
|
462
462
|
- db/migrate/20220328152900_add_failed_jobs_indicies.rb
|
463
|
+
- db/migrate/20220519204546_add_requeued_job_id_to_failed_jobs.rb
|
463
464
|
- exe/inst_jobs
|
464
465
|
- lib/delayed/backend/active_record.rb
|
465
466
|
- lib/delayed/backend/base.rb
|