inst-jobs 3.1.2 → 3.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/delayed/backend/active_record.rb +5 -1
- data/lib/delayed/backend/base.rb +7 -1
- data/lib/delayed/lifecycle.rb +7 -1
- data/lib/delayed/pool.rb +12 -2
- data/lib/delayed/server.rb +7 -1
- data/lib/delayed/version.rb +1 -1
- data/lib/delayed/work_queue/parent_process/server.rb +5 -1
- metadata +7 -55
- data/spec/active_record_job_spec.rb +0 -326
- data/spec/delayed/cli_spec.rb +0 -25
- data/spec/delayed/daemon_spec.rb +0 -38
- data/spec/delayed/message_sending_spec.rb +0 -108
- data/spec/delayed/periodic_spec.rb +0 -32
- data/spec/delayed/server_spec.rb +0 -103
- data/spec/delayed/settings_spec.rb +0 -48
- data/spec/delayed/work_queue/in_process_spec.rb +0 -31
- data/spec/delayed/work_queue/parent_process/client_spec.rb +0 -87
- data/spec/delayed/work_queue/parent_process/server_spec.rb +0 -280
- data/spec/delayed/work_queue/parent_process_spec.rb +0 -60
- data/spec/delayed/worker/consul_health_check_spec.rb +0 -63
- data/spec/delayed/worker/health_check_spec.rb +0 -134
- data/spec/delayed/worker_spec.rb +0 -106
- data/spec/migrate/20140924140513_add_story_table.rb +0 -9
- data/spec/sample_jobs.rb +0 -79
- data/spec/shared/delayed_batch.rb +0 -105
- data/spec/shared/delayed_method.rb +0 -287
- data/spec/shared/performable_method.rb +0 -75
- data/spec/shared/shared_backend.rb +0 -1238
- data/spec/shared/testing.rb +0 -50
- data/spec/shared/worker.rb +0 -413
- data/spec/shared_jobs_specs.rb +0 -17
- data/spec/spec_helper.rb +0 -138
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5adf88a85cf490a4fee0b3e8b5234be47b0f70034f6a89489ace8a132c74886d
|
4
|
+
data.tar.gz: '07836a394917c38fcb1cba64a9a1988f3c949bb7e147247f759da8f860382a7f'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fc62248de29a57be2044a0949299ac26475df434c4906f0786293bb07b3a7bf63fb1c2b79c3e230e992825984e76417eb9ad221a46bac5c78b92d305c2db638
|
7
|
+
data.tar.gz: 44a04dcfd05ecad3345bd9da25909711912edaaf16e9f6a502859765319de33e0a59ac840571b5f5e543b76ce40b43550ab9a750e56753c60c29886002894201
|
@@ -28,7 +28,11 @@ module Delayed
|
|
28
28
|
scope :next_in_strand_order, -> { order(:strand_order_override, :id) }
|
29
29
|
|
30
30
|
def self.reconnect!
|
31
|
-
|
31
|
+
if Rails.version < "6.1"
|
32
|
+
::ActiveRecord::Base.connection_handler.clear_all_connections!
|
33
|
+
else
|
34
|
+
::ActiveRecord::Base.connection_handler.clear_all_connections!(nil)
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
38
|
class << self
|
data/lib/delayed/backend/base.rb
CHANGED
@@ -312,7 +312,13 @@ module Delayed
|
|
312
312
|
payload_object.perform
|
313
313
|
ensure
|
314
314
|
Delayed::Job.in_delayed_job = false
|
315
|
-
|
315
|
+
unless Rails.env.test?
|
316
|
+
if Rails.version < "6.1"
|
317
|
+
::ActiveRecord::Base.clear_active_connections!
|
318
|
+
else
|
319
|
+
::ActiveRecord::Base.clear_active_connections!(nil)
|
320
|
+
end
|
321
|
+
end
|
316
322
|
end
|
317
323
|
end
|
318
324
|
end
|
data/lib/delayed/lifecycle.rb
CHANGED
@@ -77,7 +77,13 @@ module Delayed
|
|
77
77
|
def execute(*args, &block)
|
78
78
|
@before.each { |c| c.call(*args) }
|
79
79
|
result = @around.call(*args, &block)
|
80
|
-
@after.each
|
80
|
+
@after.each do |c|
|
81
|
+
if c.arity == args.length + 1 # don't fail for methods that don't define `result:`
|
82
|
+
c.call(*args, result: result)
|
83
|
+
else
|
84
|
+
c.call(*args)
|
85
|
+
end
|
86
|
+
end
|
81
87
|
result
|
82
88
|
end
|
83
89
|
|
data/lib/delayed/pool.rb
CHANGED
@@ -67,11 +67,21 @@ module Delayed
|
|
67
67
|
|
68
68
|
unlocked_jobs = Delayed::Job.unlock_orphaned_jobs(pid)
|
69
69
|
say "Unlocked #{unlocked_jobs} orphaned jobs" if unlocked_jobs.positive?
|
70
|
-
|
70
|
+
return if Rails.env.test?
|
71
|
+
|
72
|
+
if Rails.version < "6.1"
|
73
|
+
ActiveRecord::Base.connection_handler.clear_all_connections!
|
74
|
+
else
|
75
|
+
ActiveRecord::Base.connection_handler.clear_all_connections!(nil)
|
76
|
+
end
|
71
77
|
end
|
72
78
|
|
73
79
|
def spawn_all_workers
|
74
|
-
|
80
|
+
if Rails.version < "6.1"
|
81
|
+
ActiveRecord::Base.connection_handler.clear_all_connections!
|
82
|
+
else
|
83
|
+
ActiveRecord::Base.connection_handler.clear_all_connections!(nil)
|
84
|
+
end
|
75
85
|
|
76
86
|
if @config[:work_queue] == "parent_process"
|
77
87
|
@work_queue = WorkQueue::ParentProcess.new
|
data/lib/delayed/server.rb
CHANGED
@@ -37,7 +37,13 @@ module Delayed
|
|
37
37
|
|
38
38
|
# Release any used connections back to the pool
|
39
39
|
after do
|
40
|
-
|
40
|
+
if using_active_record?
|
41
|
+
if Rails.version < "6.1"
|
42
|
+
::ActiveRecord::Base.clear_active_connections!
|
43
|
+
else
|
44
|
+
::ActiveRecord::Base.clear_active_connections!(nil)
|
45
|
+
end
|
46
|
+
end
|
41
47
|
end
|
42
48
|
|
43
49
|
configure :development do
|
data/lib/delayed/version.rb
CHANGED
@@ -226,7 +226,11 @@ module Delayed
|
|
226
226
|
|
227
227
|
# otherwise just reconnect and let it retry
|
228
228
|
logger.warn("failed to unlock prefetched jobs - connection terminated; skipping for now")
|
229
|
-
|
229
|
+
if Rails.version < "6.1"
|
230
|
+
::Delayed::Job.clear_all_connections!
|
231
|
+
else
|
232
|
+
::Delayed::Job.clear_all_connections!(nil)
|
233
|
+
end
|
230
234
|
end
|
231
235
|
end
|
232
236
|
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inst-jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cody Cutrer
|
8
8
|
- Ethan Vizitei
|
9
9
|
- Jacob Burroughs
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2022-
|
13
|
+
date: 2022-07-07 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activerecord
|
@@ -410,7 +410,7 @@ dependencies:
|
|
410
410
|
- - ">="
|
411
411
|
- !ruby/object:Gem::Version
|
412
412
|
version: '0'
|
413
|
-
description:
|
413
|
+
description:
|
414
414
|
email:
|
415
415
|
- cody@instructure.com
|
416
416
|
- evizitei@instructure.com
|
@@ -500,35 +500,11 @@ files:
|
|
500
500
|
- lib/delayed/yaml_extensions.rb
|
501
501
|
- lib/delayed_job.rb
|
502
502
|
- lib/inst-jobs.rb
|
503
|
-
- spec/active_record_job_spec.rb
|
504
|
-
- spec/delayed/cli_spec.rb
|
505
|
-
- spec/delayed/daemon_spec.rb
|
506
|
-
- spec/delayed/message_sending_spec.rb
|
507
|
-
- spec/delayed/periodic_spec.rb
|
508
|
-
- spec/delayed/server_spec.rb
|
509
|
-
- spec/delayed/settings_spec.rb
|
510
|
-
- spec/delayed/work_queue/in_process_spec.rb
|
511
|
-
- spec/delayed/work_queue/parent_process/client_spec.rb
|
512
|
-
- spec/delayed/work_queue/parent_process/server_spec.rb
|
513
|
-
- spec/delayed/work_queue/parent_process_spec.rb
|
514
|
-
- spec/delayed/worker/consul_health_check_spec.rb
|
515
|
-
- spec/delayed/worker/health_check_spec.rb
|
516
|
-
- spec/delayed/worker_spec.rb
|
517
|
-
- spec/migrate/20140924140513_add_story_table.rb
|
518
|
-
- spec/sample_jobs.rb
|
519
|
-
- spec/shared/delayed_batch.rb
|
520
|
-
- spec/shared/delayed_method.rb
|
521
|
-
- spec/shared/performable_method.rb
|
522
|
-
- spec/shared/shared_backend.rb
|
523
|
-
- spec/shared/testing.rb
|
524
|
-
- spec/shared/worker.rb
|
525
|
-
- spec/shared_jobs_specs.rb
|
526
|
-
- spec/spec_helper.rb
|
527
503
|
homepage: https://github.com/instructure/inst-jobs
|
528
504
|
licenses: []
|
529
505
|
metadata:
|
530
506
|
rubygems_mfa_required: 'true'
|
531
|
-
post_install_message:
|
507
|
+
post_install_message:
|
532
508
|
rdoc_options: []
|
533
509
|
require_paths:
|
534
510
|
- lib
|
@@ -544,31 +520,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
544
520
|
version: '0'
|
545
521
|
requirements: []
|
546
522
|
rubygems_version: 3.1.6
|
547
|
-
signing_key:
|
523
|
+
signing_key:
|
548
524
|
specification_version: 4
|
549
525
|
summary: Instructure-maintained fork of delayed_job
|
550
|
-
test_files:
|
551
|
-
- spec/active_record_job_spec.rb
|
552
|
-
- spec/delayed/cli_spec.rb
|
553
|
-
- spec/delayed/daemon_spec.rb
|
554
|
-
- spec/delayed/message_sending_spec.rb
|
555
|
-
- spec/delayed/periodic_spec.rb
|
556
|
-
- spec/delayed/server_spec.rb
|
557
|
-
- spec/delayed/settings_spec.rb
|
558
|
-
- spec/delayed/work_queue/in_process_spec.rb
|
559
|
-
- spec/delayed/work_queue/parent_process/client_spec.rb
|
560
|
-
- spec/delayed/work_queue/parent_process/server_spec.rb
|
561
|
-
- spec/delayed/work_queue/parent_process_spec.rb
|
562
|
-
- spec/delayed/worker/consul_health_check_spec.rb
|
563
|
-
- spec/delayed/worker/health_check_spec.rb
|
564
|
-
- spec/delayed/worker_spec.rb
|
565
|
-
- spec/migrate/20140924140513_add_story_table.rb
|
566
|
-
- spec/sample_jobs.rb
|
567
|
-
- spec/shared/delayed_batch.rb
|
568
|
-
- spec/shared/delayed_method.rb
|
569
|
-
- spec/shared/performable_method.rb
|
570
|
-
- spec/shared/shared_backend.rb
|
571
|
-
- spec/shared/testing.rb
|
572
|
-
- spec/shared/worker.rb
|
573
|
-
- spec/shared_jobs_specs.rb
|
574
|
-
- spec/spec_helper.rb
|
526
|
+
test_files: []
|
@@ -1,326 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
describe "Delayed::Backed::ActiveRecord::Job" do
|
4
|
-
before :all do
|
5
|
-
Delayed.select_backend(Delayed::Backend::ActiveRecord::Job)
|
6
|
-
end
|
7
|
-
|
8
|
-
before do
|
9
|
-
Delayed::Testing.clear_all!
|
10
|
-
end
|
11
|
-
|
12
|
-
include_examples "a delayed_jobs implementation"
|
13
|
-
|
14
|
-
it "recovers as well as possible from a failure failing a job" do
|
15
|
-
allow(Delayed::Job::Failed).to receive(:create).and_raise(RuntimeError)
|
16
|
-
job = "test".delay(ignore_transaction: true).reverse
|
17
|
-
job_id = job.id
|
18
|
-
expect { job.fail! }.to raise_error(RuntimeError)
|
19
|
-
expect { Delayed::Job.find(job_id) }.to raise_error(ActiveRecord::RecordNotFound)
|
20
|
-
expect(Delayed::Job.count).to eq(0)
|
21
|
-
end
|
22
|
-
|
23
|
-
context "when another worker has worked on a task since the job was found to be available, it" do
|
24
|
-
before do
|
25
|
-
@job = Delayed::Job.create payload_object: SimpleJob.new
|
26
|
-
@job_copy_for_worker2 = Delayed::Job.find(@job.id)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "does not allow a second worker to get exclusive access if already successfully processed by worker1" do
|
30
|
-
@job.destroy
|
31
|
-
expect(@job_copy_for_worker2.send(:lock_exclusively!, "worker2")).to be(false)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "doesn't allow a second worker to get exclusive access if failed to be " \
|
35
|
-
"processed by worker1 and run_at time is now in future (due to backing off behaviour)" do
|
36
|
-
@job.update(attempts: 1, run_at: 1.day.from_now)
|
37
|
-
expect(@job_copy_for_worker2.send(:lock_exclusively!, "worker2")).to be(false)
|
38
|
-
end
|
39
|
-
|
40
|
-
it "selects the next job at random if enabled" do
|
41
|
-
Delayed::Settings.select_random_from_batch = true
|
42
|
-
15.times { "test".delay.length }
|
43
|
-
founds = []
|
44
|
-
15.times do
|
45
|
-
job = Delayed::Job.get_and_lock_next_available("tester")
|
46
|
-
founds << job
|
47
|
-
job.unlock
|
48
|
-
job.save!
|
49
|
-
end
|
50
|
-
expect(founds.uniq.size).to be > 1
|
51
|
-
ensure
|
52
|
-
Delayed::Settings.select_random_from_batch = false
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
it "unlocks a successfully locked job and persist the job's unlocked state" do
|
57
|
-
job = Delayed::Job.create payload_object: SimpleJob.new
|
58
|
-
expect(job.send(:lock_exclusively!, "worker1")).to be(true)
|
59
|
-
job.reload
|
60
|
-
job.unlock
|
61
|
-
job.save!
|
62
|
-
job.reload
|
63
|
-
expect(job.locked_by).to be_nil
|
64
|
-
expect(job.locked_at).to be_nil
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "bulk_update failed jobs" do
|
68
|
-
context "holding/unholding failed jobs" do
|
69
|
-
before do
|
70
|
-
@job = Delayed::Job.create payload_object: SimpleJob.new
|
71
|
-
expect(Delayed::Job.get_and_lock_next_available("worker1")).to eq(@job)
|
72
|
-
@job.fail!
|
73
|
-
end
|
74
|
-
|
75
|
-
it "raises error when holding failed jobs" do
|
76
|
-
expect { Delayed::Job.bulk_update("hold", flavor: "failed", query: @query) }.to raise_error(RuntimeError)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "raises error unholding failed jobs" do
|
80
|
-
expect { Delayed::Job.bulk_update("unhold", flavor: "failed", query: @query) }.to raise_error(RuntimeError)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "deleting failed jobs" do
|
85
|
-
before do
|
86
|
-
2.times do
|
87
|
-
j = Delayed::Job.create(payload_object: SimpleJob.new)
|
88
|
-
expect(j.send(:lock_exclusively!, "worker1")).to be(true)
|
89
|
-
j.fail!
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
it "deletes failed jobs by id" do
|
94
|
-
target_ids = Delayed::Job::Failed.all[0..2].map(&:id)
|
95
|
-
expect(Delayed::Job.bulk_update("destroy", ids: target_ids, flavor: "failed",
|
96
|
-
query: @query)).to eq(target_ids.length)
|
97
|
-
end
|
98
|
-
|
99
|
-
it "deletes all failed jobs" do
|
100
|
-
failed_count = Delayed::Job::Failed.count
|
101
|
-
expect(Delayed::Job.bulk_update("destroy", flavor: "failed", query: @query)).to eq(failed_count)
|
102
|
-
end
|
103
|
-
|
104
|
-
it "deletes all failed jobs before a given date" do
|
105
|
-
Delayed::Job::Failed.first.update!(failed_at: 3.hours.ago)
|
106
|
-
Delayed::Job::Failed.last.update!(failed_at: 1.hour.ago)
|
107
|
-
|
108
|
-
expect(Delayed::Job::Failed.count).to eq 2
|
109
|
-
Delayed::Job::Failed.cleanup_old_jobs(2.hours.ago)
|
110
|
-
expect(Delayed::Job::Failed.count).to eq 1
|
111
|
-
end
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
context "n_strand" do
|
116
|
-
it "defaults to 1" do
|
117
|
-
expect(Delayed::Job).not_to receive(:rand)
|
118
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: "njobs")
|
119
|
-
expect(job.strand).to eq("njobs")
|
120
|
-
end
|
121
|
-
|
122
|
-
it "sets max_concurrent based on num_strands" do
|
123
|
-
change_setting(Delayed::Settings, :num_strands, lambda { |strand_name|
|
124
|
-
expect(strand_name).to eql "njobs"
|
125
|
-
"3"
|
126
|
-
}) do
|
127
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: "njobs")
|
128
|
-
expect(job.strand).to eq("njobs")
|
129
|
-
expect(job.max_concurrent).to eq(3)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
context "with two parameters" do
|
134
|
-
it "uses the first param as the setting to read" do
|
135
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: %w[njobs 123])
|
136
|
-
expect(job.strand).to eq("njobs/123")
|
137
|
-
change_setting(Delayed::Settings, :num_strands, lambda { |strand_name|
|
138
|
-
case strand_name
|
139
|
-
when "njobs" then 3
|
140
|
-
end
|
141
|
-
}) do
|
142
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: %w[njobs 123])
|
143
|
-
expect(job.strand).to eq("njobs/123")
|
144
|
-
expect(job.max_concurrent).to eq(3)
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
it "allows overridding the setting based on the second param" do
|
149
|
-
change_setting(Delayed::Settings, :num_strands, lambda { |strand_name|
|
150
|
-
case strand_name
|
151
|
-
when "njobs/123" then 5
|
152
|
-
end
|
153
|
-
}) do
|
154
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: %w[njobs 123])
|
155
|
-
expect(job.strand).to eq("njobs/123")
|
156
|
-
expect(job.max_concurrent).to eq(5)
|
157
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: %w[njobs 456])
|
158
|
-
expect(job.strand).to eq("njobs/456")
|
159
|
-
expect(job.max_concurrent).to eq(1)
|
160
|
-
end
|
161
|
-
|
162
|
-
change_setting(Delayed::Settings, :num_strands, lambda { |strand_name|
|
163
|
-
case strand_name
|
164
|
-
when "njobs/123" then 5
|
165
|
-
when "njobs" then 3
|
166
|
-
end
|
167
|
-
}) do
|
168
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: %w[njobs 123])
|
169
|
-
expect(job.strand).to eq("njobs/123")
|
170
|
-
expect(job.max_concurrent).to eq(5)
|
171
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: %w[njobs 456])
|
172
|
-
expect(job.strand).to eq("njobs/456")
|
173
|
-
expect(job.max_concurrent).to eq(3)
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
context "max_concurrent triggers" do
|
179
|
-
it "sets one job as next_in_strand at a time with max_concurrent of 1" do
|
180
|
-
job1 = Delayed::Job.enqueue(SimpleJob.new, n_strand: ["njobs"])
|
181
|
-
job1.reload
|
182
|
-
expect(job1.next_in_strand).to be(true)
|
183
|
-
job2 = Delayed::Job.enqueue(SimpleJob.new, n_strand: ["njobs"])
|
184
|
-
job2.reload
|
185
|
-
expect(job2.next_in_strand).to be(false)
|
186
|
-
run_job(job1)
|
187
|
-
job2.reload
|
188
|
-
expect(job2.next_in_strand).to be(true)
|
189
|
-
end
|
190
|
-
|
191
|
-
it "sets multiple jobs as next_in_strand at a time based on max_concurrent" do
|
192
|
-
change_setting(Delayed::Settings, :num_strands, lambda { |strand_name|
|
193
|
-
case strand_name
|
194
|
-
when "njobs" then 2
|
195
|
-
end
|
196
|
-
}) do
|
197
|
-
job1 = Delayed::Job.enqueue(SimpleJob.new, n_strand: ["njobs"])
|
198
|
-
job1.reload
|
199
|
-
expect(job1.next_in_strand).to be(true)
|
200
|
-
job2 = Delayed::Job.enqueue(SimpleJob.new, n_strand: ["njobs"])
|
201
|
-
job2.reload
|
202
|
-
expect(job2.next_in_strand).to be(true)
|
203
|
-
job3 = Delayed::Job.enqueue(SimpleJob.new, n_strand: ["njobs"])
|
204
|
-
job3.reload
|
205
|
-
expect(job3.next_in_strand).to be(false)
|
206
|
-
run_job(job1)
|
207
|
-
job3.reload
|
208
|
-
expect(job3.next_in_strand).to be(true)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
it "unlocks orphaned prefetched_jobs" do
|
215
|
-
job1 = Delayed::Job.new(tag: "tag")
|
216
|
-
job2 = Delayed::Job.new(tag: "tag")
|
217
|
-
|
218
|
-
job1.create_and_lock!("prefetch:a")
|
219
|
-
job1.locked_at = Delayed::Job.db_time_now - (15 * 60)
|
220
|
-
job1.save!
|
221
|
-
job2.create_and_lock!("prefetch:a")
|
222
|
-
|
223
|
-
expect(Delayed::Job.unlock_orphaned_prefetched_jobs).to eq 1
|
224
|
-
expect(Delayed::Job.unlock_orphaned_prefetched_jobs).to eq 0
|
225
|
-
|
226
|
-
expect(Delayed::Job.find(job1.id).locked_by).to be_nil
|
227
|
-
expect(Delayed::Job.find(job2.id).locked_by).to eq "prefetch:a"
|
228
|
-
end
|
229
|
-
|
230
|
-
it "gets process ids from locked_by" do
|
231
|
-
Array.new(3) { Delayed::Job.create payload_object: SimpleJob.new }
|
232
|
-
Delayed::Job.get_and_lock_next_available(["job42:2", "job42:9001"])
|
233
|
-
expect(Delayed::Job.processes_locked_locally(name: "job42").sort).to eq [2, 9001]
|
234
|
-
expect(Delayed::Job.processes_locked_locally(name: "jobnotme")).to be_empty
|
235
|
-
end
|
236
|
-
|
237
|
-
it "allows fetching multiple jobs at once" do
|
238
|
-
jobs = Array.new(3) { Delayed::Job.create payload_object: SimpleJob.new }
|
239
|
-
locked_jobs = Delayed::Job.get_and_lock_next_available(%w[worker1 worker2])
|
240
|
-
expect(locked_jobs.length).to eq(2)
|
241
|
-
expect(locked_jobs.keys).to eq(%w[worker1 worker2])
|
242
|
-
expect(locked_jobs.values).to eq(jobs[0..1])
|
243
|
-
expect(jobs.map(&:reload).map(&:locked_by)).to eq(["worker1", "worker2", nil])
|
244
|
-
end
|
245
|
-
|
246
|
-
it "allows fetching extra jobs" do
|
247
|
-
jobs = Array.new(5) { Delayed::Job.create payload_object: SimpleJob.new }
|
248
|
-
locked_jobs = Delayed::Job.get_and_lock_next_available(["worker1"],
|
249
|
-
prefetch: 2,
|
250
|
-
prefetch_owner: "work_queue")
|
251
|
-
expect(locked_jobs.length).to eq 2
|
252
|
-
expect(locked_jobs.keys).to eq %w[worker1 work_queue]
|
253
|
-
expect(locked_jobs["worker1"]).to eq jobs[0]
|
254
|
-
expect(locked_jobs["work_queue"]).to eq jobs[1..2]
|
255
|
-
expect(jobs.map(&:reload).map(&:locked_by)).to eq(["worker1", "work_queue", "work_queue", nil, nil])
|
256
|
-
end
|
257
|
-
|
258
|
-
it "does not find jobs scheduled for now when we have forced latency" do
|
259
|
-
job = create_job
|
260
|
-
expect(Delayed::Job.get_and_lock_next_available("worker", forced_latency: 60.0)).to be_nil
|
261
|
-
expect(Delayed::Job.get_and_lock_next_available("worker")).to eq job
|
262
|
-
end
|
263
|
-
|
264
|
-
context "non-transactional", non_transactional: true do
|
265
|
-
it "creates a stranded job in a single statement" do
|
266
|
-
allow(Delayed::Job.connection).to receive(:prepared_statements).and_return(false)
|
267
|
-
allow(Delayed::Job.connection).to receive(:execute).with(be_include("pg_advisory_xact_lock"),
|
268
|
-
anything).and_call_original.once
|
269
|
-
expect(Delayed::Job.connection).not_to receive(:insert)
|
270
|
-
j = create_job(strand: "test1")
|
271
|
-
allow(Delayed::Job.connection).to receive(:execute).and_call_original
|
272
|
-
expect(Delayed::Job.find(j.id)).to eq j
|
273
|
-
end
|
274
|
-
|
275
|
-
it "creates a non-stranded job in a single statement" do
|
276
|
-
allow(Delayed::Job.connection).to receive(:prepared_statements).and_return(false)
|
277
|
-
call_count = 0
|
278
|
-
allow(Delayed::Job.connection).to receive(:execute).and_wrap_original do |m, (arg1, arg2)|
|
279
|
-
call_count += 1
|
280
|
-
m.call(arg1, arg2)
|
281
|
-
end
|
282
|
-
expect(Delayed::Job.connection).not_to receive(:insert)
|
283
|
-
j = create_job(strand: "test1")
|
284
|
-
expect(call_count).to eq 1
|
285
|
-
expect(Delayed::Job.find(j.id)).to eq j
|
286
|
-
end
|
287
|
-
|
288
|
-
it "does not lock a stranded failed job creation" do
|
289
|
-
j = create_job(strand: "test1")
|
290
|
-
# query for metadata to ensure it's loaded before we start mucking with the connection
|
291
|
-
Delayed::Backend::ActiveRecord::Job::Failed.new
|
292
|
-
|
293
|
-
allow(Delayed::Job.connection).to receive(:prepared_statements).and_return(false)
|
294
|
-
allow(Delayed::Job.connection).to receive(:execute).and_wrap_original do |original, *args|
|
295
|
-
expect(args.first).not_to include("pg_advisory_xact_lock")
|
296
|
-
original.call(*args)
|
297
|
-
end
|
298
|
-
expect(Delayed::Job.connection).not_to receive(:insert)
|
299
|
-
j.fail!
|
300
|
-
allow(Delayed::Job.connection).to receive(:execute).and_call_original
|
301
|
-
end
|
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
|
326
|
-
end
|
data/spec/delayed/cli_spec.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
RSpec.describe Delayed::CLI do
|
6
|
-
describe "#parse_cli_options!" do
|
7
|
-
it "correctly parses the --config option" do
|
8
|
-
cli = described_class.new(%w[run --config /path/to/some/file.yml])
|
9
|
-
options = cli.parse_cli_options!
|
10
|
-
expect(options).to include config_file: "/path/to/some/file.yml"
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#run" do
|
15
|
-
before do
|
16
|
-
expect(Delayed::Settings).to receive(:worker_config).and_return({})
|
17
|
-
end
|
18
|
-
|
19
|
-
it "prints help when no command is given" do
|
20
|
-
cli = described_class.new([])
|
21
|
-
expect(cli).to receive(:puts).with(/Usage/)
|
22
|
-
cli.run
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
data/spec/delayed/daemon_spec.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
RSpec.describe Delayed::Daemon do
|
6
|
-
subject { described_class.new(pid_folder) }
|
7
|
-
|
8
|
-
let(:pid_folder) { "/test/pid/folder" }
|
9
|
-
let(:pid) { 9999 }
|
10
|
-
|
11
|
-
before do
|
12
|
-
allow(subject).to receive(:pid).and_return(pid)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#stop" do
|
16
|
-
it "prints status if not running" do
|
17
|
-
expect(subject).to receive(:status).with(print: false, pid: pid).and_return(false)
|
18
|
-
expect(subject).to receive(:status).with(no_args)
|
19
|
-
expect(Process).not_to receive(:kill)
|
20
|
-
subject.stop
|
21
|
-
end
|
22
|
-
|
23
|
-
it "prints status if draining" do
|
24
|
-
expect(subject).to receive(:status).with(print: false, pid: pid).and_return(:draining)
|
25
|
-
expect(subject).to receive(:status).with(no_args)
|
26
|
-
expect(Process).not_to receive(:kill)
|
27
|
-
subject.stop
|
28
|
-
end
|
29
|
-
|
30
|
-
it "sends QUIT by default" do
|
31
|
-
expect(subject).to receive(:status).with(print: false, pid: pid).and_return(:running)
|
32
|
-
expect(subject).to receive(:puts).with(/Stopping pool/)
|
33
|
-
expect(Process).to receive(:kill).with("QUIT", pid)
|
34
|
-
expect(subject).to receive(:wait).with(false)
|
35
|
-
subject.stop
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|