inst-jobs 3.0.8 → 3.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +4 -2
- data/db/migrate/20200825011002_add_strand_order_override.rb +2 -1
- data/db/migrate/20210809145804_add_n_strand_index.rb +2 -1
- data/db/migrate/20220328152900_add_failed_jobs_indicies.rb +12 -0
- data/db/migrate/20220519204546_add_requeued_job_id_to_failed_jobs.rb +7 -0
- data/lib/delayed/backend/active_record.rb +77 -7
- data/lib/delayed/backend/base.rb +28 -10
- data/lib/delayed/batch.rb +1 -1
- data/lib/delayed/cli.rb +3 -2
- data/lib/delayed/lifecycle.rb +9 -2
- data/lib/delayed/log_tailer.rb +2 -2
- data/lib/delayed/message_sending.rb +9 -6
- data/lib/delayed/performable_method.rb +22 -16
- data/lib/delayed/periodic.rb +2 -2
- data/lib/delayed/pool.rb +12 -2
- data/lib/delayed/server.rb +8 -2
- data/lib/delayed/settings.rb +5 -1
- data/lib/delayed/version.rb +1 -1
- data/lib/delayed/work_queue/parent_process/server.rb +7 -3
- data/lib/delayed/worker/health_check.rb +1 -1
- data/lib/delayed/worker/process_helper.rb +4 -4
- data/lib/delayed/worker.rb +22 -11
- metadata +18 -119
- data/spec/active_record_job_spec.rb +0 -294
- 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 -105
- 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 -1221
- 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 -136
@@ -1,294 +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 eq(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 eq(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 eq(true)
|
59
|
-
job.reload
|
60
|
-
job.unlock
|
61
|
-
job.save!
|
62
|
-
job.reload
|
63
|
-
expect(job.locked_by).to eq(nil)
|
64
|
-
expect(job.locked_at).to eq(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 eq(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
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
context "n_strand" do
|
107
|
-
it "defaults to 1" do
|
108
|
-
expect(Delayed::Job).not_to receive(:rand)
|
109
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: "njobs")
|
110
|
-
expect(job.strand).to eq("njobs")
|
111
|
-
end
|
112
|
-
|
113
|
-
it "sets max_concurrent based on num_strands" do
|
114
|
-
change_setting(Delayed::Settings, :num_strands, lambda { |strand_name|
|
115
|
-
expect(strand_name).to eql "njobs"
|
116
|
-
"3"
|
117
|
-
}) do
|
118
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: "njobs")
|
119
|
-
expect(job.strand).to eq("njobs")
|
120
|
-
expect(job.max_concurrent).to eq(3)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
context "with two parameters" do
|
125
|
-
it "uses the first param as the setting to read" do
|
126
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: %w[njobs 123])
|
127
|
-
expect(job.strand).to eq("njobs/123")
|
128
|
-
change_setting(Delayed::Settings, :num_strands, lambda { |strand_name|
|
129
|
-
case strand_name
|
130
|
-
when "njobs" then 3
|
131
|
-
end
|
132
|
-
}) do
|
133
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: %w[njobs 123])
|
134
|
-
expect(job.strand).to eq("njobs/123")
|
135
|
-
expect(job.max_concurrent).to eq(3)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
it "allows overridding the setting based on the second param" do
|
140
|
-
change_setting(Delayed::Settings, :num_strands, lambda { |strand_name|
|
141
|
-
case strand_name
|
142
|
-
when "njobs/123" then 5
|
143
|
-
end
|
144
|
-
}) do
|
145
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: %w[njobs 123])
|
146
|
-
expect(job.strand).to eq("njobs/123")
|
147
|
-
expect(job.max_concurrent).to eq(5)
|
148
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: %w[njobs 456])
|
149
|
-
expect(job.strand).to eq("njobs/456")
|
150
|
-
expect(job.max_concurrent).to eq(1)
|
151
|
-
end
|
152
|
-
|
153
|
-
change_setting(Delayed::Settings, :num_strands, lambda { |strand_name|
|
154
|
-
case strand_name
|
155
|
-
when "njobs/123" then 5
|
156
|
-
when "njobs" then 3
|
157
|
-
end
|
158
|
-
}) do
|
159
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: %w[njobs 123])
|
160
|
-
expect(job.strand).to eq("njobs/123")
|
161
|
-
expect(job.max_concurrent).to eq(5)
|
162
|
-
job = Delayed::Job.enqueue(SimpleJob.new, n_strand: %w[njobs 456])
|
163
|
-
expect(job.strand).to eq("njobs/456")
|
164
|
-
expect(job.max_concurrent).to eq(3)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
context "max_concurrent triggers" do
|
170
|
-
it "sets one job as next_in_strand at a time with max_concurrent of 1" do
|
171
|
-
job1 = Delayed::Job.enqueue(SimpleJob.new, n_strand: ["njobs"])
|
172
|
-
job1.reload
|
173
|
-
expect(job1.next_in_strand).to eq(true)
|
174
|
-
job2 = Delayed::Job.enqueue(SimpleJob.new, n_strand: ["njobs"])
|
175
|
-
job2.reload
|
176
|
-
expect(job2.next_in_strand).to eq(false)
|
177
|
-
run_job(job1)
|
178
|
-
job2.reload
|
179
|
-
expect(job2.next_in_strand).to eq(true)
|
180
|
-
end
|
181
|
-
|
182
|
-
it "sets multiple jobs as next_in_strand at a time based on max_concurrent" do
|
183
|
-
change_setting(Delayed::Settings, :num_strands, lambda { |strand_name|
|
184
|
-
case strand_name
|
185
|
-
when "njobs" then 2
|
186
|
-
end
|
187
|
-
}) do
|
188
|
-
job1 = Delayed::Job.enqueue(SimpleJob.new, n_strand: ["njobs"])
|
189
|
-
job1.reload
|
190
|
-
expect(job1.next_in_strand).to eq(true)
|
191
|
-
job2 = Delayed::Job.enqueue(SimpleJob.new, n_strand: ["njobs"])
|
192
|
-
job2.reload
|
193
|
-
expect(job2.next_in_strand).to eq(true)
|
194
|
-
job3 = Delayed::Job.enqueue(SimpleJob.new, n_strand: ["njobs"])
|
195
|
-
job3.reload
|
196
|
-
expect(job3.next_in_strand).to eq(false)
|
197
|
-
run_job(job1)
|
198
|
-
job3.reload
|
199
|
-
expect(job3.next_in_strand).to eq(true)
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
it "unlocks orphaned prefetched_jobs" do
|
206
|
-
job1 = Delayed::Job.new(tag: "tag")
|
207
|
-
job2 = Delayed::Job.new(tag: "tag")
|
208
|
-
|
209
|
-
job1.create_and_lock!("prefetch:a")
|
210
|
-
job1.locked_at = Delayed::Job.db_time_now - (15 * 60)
|
211
|
-
job1.save!
|
212
|
-
job2.create_and_lock!("prefetch:a")
|
213
|
-
|
214
|
-
expect(Delayed::Job.unlock_orphaned_prefetched_jobs).to eq 1
|
215
|
-
expect(Delayed::Job.unlock_orphaned_prefetched_jobs).to eq 0
|
216
|
-
|
217
|
-
expect(Delayed::Job.find(job1.id).locked_by).to be_nil
|
218
|
-
expect(Delayed::Job.find(job2.id).locked_by).to eq "prefetch:a"
|
219
|
-
end
|
220
|
-
|
221
|
-
it "gets process ids from locked_by" do
|
222
|
-
Array.new(3) { Delayed::Job.create payload_object: SimpleJob.new }
|
223
|
-
Delayed::Job.get_and_lock_next_available(["job42:2", "job42:9001"])
|
224
|
-
expect(Delayed::Job.processes_locked_locally(name: "job42").sort).to eq [2, 9001]
|
225
|
-
expect(Delayed::Job.processes_locked_locally(name: "jobnotme")).to be_empty
|
226
|
-
end
|
227
|
-
|
228
|
-
it "allows fetching multiple jobs at once" do
|
229
|
-
jobs = Array.new(3) { Delayed::Job.create payload_object: SimpleJob.new }
|
230
|
-
locked_jobs = Delayed::Job.get_and_lock_next_available(%w[worker1 worker2])
|
231
|
-
expect(locked_jobs.length).to eq(2)
|
232
|
-
expect(locked_jobs.keys).to eq(%w[worker1 worker2])
|
233
|
-
expect(locked_jobs.values).to eq(jobs[0..1])
|
234
|
-
expect(jobs.map(&:reload).map(&:locked_by)).to eq(["worker1", "worker2", nil])
|
235
|
-
end
|
236
|
-
|
237
|
-
it "allows fetching extra jobs" do
|
238
|
-
jobs = Array.new(5) { Delayed::Job.create payload_object: SimpleJob.new }
|
239
|
-
locked_jobs = Delayed::Job.get_and_lock_next_available(["worker1"],
|
240
|
-
prefetch: 2,
|
241
|
-
prefetch_owner: "work_queue")
|
242
|
-
expect(locked_jobs.length).to eq 2
|
243
|
-
expect(locked_jobs.keys).to eq %w[worker1 work_queue]
|
244
|
-
expect(locked_jobs["worker1"]).to eq jobs[0]
|
245
|
-
expect(locked_jobs["work_queue"]).to eq jobs[1..2]
|
246
|
-
expect(jobs.map(&:reload).map(&:locked_by)).to eq(["worker1", "work_queue", "work_queue", nil, nil])
|
247
|
-
end
|
248
|
-
|
249
|
-
it "does not find jobs scheduled for now when we have forced latency" do
|
250
|
-
job = create_job
|
251
|
-
expect(Delayed::Job.get_and_lock_next_available("worker", forced_latency: 60.0)).to be_nil
|
252
|
-
expect(Delayed::Job.get_and_lock_next_available("worker")).to eq job
|
253
|
-
end
|
254
|
-
|
255
|
-
context "non-transactional", non_transactional: true do
|
256
|
-
it "creates a stranded job in a single statement" do
|
257
|
-
allow(Delayed::Job.connection).to receive(:prepared_statements).and_return(false)
|
258
|
-
allow(Delayed::Job.connection).to receive(:execute).with(be_include("pg_advisory_xact_lock"),
|
259
|
-
anything).and_call_original.once
|
260
|
-
expect(Delayed::Job.connection).not_to receive(:insert)
|
261
|
-
j = create_job(strand: "test1")
|
262
|
-
allow(Delayed::Job.connection).to receive(:execute).and_call_original
|
263
|
-
expect(Delayed::Job.find(j.id)).to eq j
|
264
|
-
end
|
265
|
-
|
266
|
-
it "creates a non-stranded job in a single statement" do
|
267
|
-
allow(Delayed::Job.connection).to receive(:prepared_statements).and_return(false)
|
268
|
-
call_count = 0
|
269
|
-
allow(Delayed::Job.connection).to receive(:execute).and_wrap_original do |m, (arg1, arg2)|
|
270
|
-
call_count += 1
|
271
|
-
m.call(arg1, arg2)
|
272
|
-
end
|
273
|
-
expect(Delayed::Job.connection).not_to receive(:insert)
|
274
|
-
j = create_job(strand: "test1")
|
275
|
-
expect(call_count).to eq 1
|
276
|
-
expect(Delayed::Job.find(j.id)).to eq j
|
277
|
-
end
|
278
|
-
|
279
|
-
it "does not lock a stranded failed job creation" do
|
280
|
-
j = create_job(strand: "test1")
|
281
|
-
# query for metadata to ensure it's loaded before we start mucking with the connection
|
282
|
-
Delayed::Backend::ActiveRecord::Job::Failed.new
|
283
|
-
|
284
|
-
allow(Delayed::Job.connection).to receive(:prepared_statements).and_return(false)
|
285
|
-
allow(Delayed::Job.connection).to receive(:execute).and_wrap_original do |original, *args|
|
286
|
-
expect(args.first).not_to include("pg_advisory_xact_lock")
|
287
|
-
original.call(*args)
|
288
|
-
end
|
289
|
-
expect(Delayed::Job.connection).not_to receive(:insert)
|
290
|
-
j.fail!
|
291
|
-
allow(Delayed::Job.connection).to receive(:execute).and_call_original
|
292
|
-
end
|
293
|
-
end
|
294
|
-
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
|
@@ -1,108 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
require "debug_inspector"
|
5
|
-
|
6
|
-
RSpec.describe Delayed::MessageSending do
|
7
|
-
before do
|
8
|
-
allow(::Rails.env).to receive(:test?).and_return(true)
|
9
|
-
end
|
10
|
-
|
11
|
-
before(:all) do
|
12
|
-
# this has to be a "real" constant
|
13
|
-
class SpecClass # rubocop:disable RSpec/LeakyConstantDeclaration, Lint/ConstantDefinitionInBlock
|
14
|
-
def call_private(**enqueue_args)
|
15
|
-
delay(**enqueue_args).private_method
|
16
|
-
end
|
17
|
-
|
18
|
-
def call_protected(**enqueue_args)
|
19
|
-
other = self.class.new
|
20
|
-
other.delay(**enqueue_args).protected_method
|
21
|
-
end
|
22
|
-
|
23
|
-
def call_public(**_kwargs)
|
24
|
-
42
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def private_method; end
|
30
|
-
|
31
|
-
protected
|
32
|
-
|
33
|
-
def protected_method; end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
after(:all) do
|
38
|
-
Object.send(:remove_const, :SpecClass)
|
39
|
-
end
|
40
|
-
|
41
|
-
let(:klass) { SpecClass }
|
42
|
-
|
43
|
-
it "allows an object to send a private message to itself" do
|
44
|
-
job = klass.new.call_private(ignore_transaction: true)
|
45
|
-
job.invoke_job
|
46
|
-
end
|
47
|
-
|
48
|
-
it "allows an object to send a private message to itself synchronouosly" do
|
49
|
-
klass.new.call_private(synchronous: true)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "warns about directly sending a private message asynchronously" do
|
53
|
-
expect { klass.new.delay.private_method }.to raise_error(NoMethodError)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "warns about directly sending a private message synchronusly" do
|
57
|
-
expect { klass.new.delay(synchronous: true).private_method }.to raise_error(NoMethodError)
|
58
|
-
end
|
59
|
-
|
60
|
-
it "does not warn about directly sending a private message in production" do
|
61
|
-
allow(::Rails.env).to receive(:test?).and_return(false)
|
62
|
-
allow(::Rails.env).to receive(:development?).and_return(false)
|
63
|
-
klass.new.delay.private_method
|
64
|
-
end
|
65
|
-
|
66
|
-
it "does not warn about directly sending a private message synchronously in production" do
|
67
|
-
allow(::Rails.env).to receive(:test?).and_return(false)
|
68
|
-
allow(::Rails.env).to receive(:development?).and_return(false)
|
69
|
-
klass.new.delay(synchronous: true).private_method
|
70
|
-
end
|
71
|
-
|
72
|
-
it "allows an object to send a protected message to itself" do
|
73
|
-
job = klass.new.call_protected(ignore_transaction: true)
|
74
|
-
job.invoke_job
|
75
|
-
end
|
76
|
-
|
77
|
-
it "allows an object to send a protected message to itself synchronouosly" do
|
78
|
-
klass.new.call_protected(synchronous: true)
|
79
|
-
end
|
80
|
-
|
81
|
-
it "directly calls a public method on an object with kwargs" do
|
82
|
-
expect(klass.new.delay(synchronous: true).call_public(kwarg: 10)).to eq 42
|
83
|
-
end
|
84
|
-
|
85
|
-
it "warns about directly sending a protected message asynchronously" do
|
86
|
-
expect { klass.new.delay.protected_method }.to raise_error(NoMethodError)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "warns about directly sending a protected message synchronusly" do
|
90
|
-
expect { klass.new.delay(synchronous: true).protected_method }.to raise_error(NoMethodError)
|
91
|
-
end
|
92
|
-
|
93
|
-
it "doesn't explode if you can't dump the sender" do
|
94
|
-
klass = Class.new do
|
95
|
-
def delay_something
|
96
|
-
Kernel.delay.sleep(1)
|
97
|
-
end
|
98
|
-
|
99
|
-
def encode_with(_encoder)
|
100
|
-
raise "yaml encoding failed"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
obj = klass.new
|
105
|
-
expect { YAML.dump(obj) }.to raise_error("yaml encoding failed")
|
106
|
-
expect { obj.delay_something }.not_to raise_error
|
107
|
-
end
|
108
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
RSpec.describe Delayed::Periodic do
|
6
|
-
around do |block|
|
7
|
-
# make sure we can use ".cron" and
|
8
|
-
# such safely without leaking global state
|
9
|
-
prev_sched = described_class.scheduled
|
10
|
-
prev_ovr = described_class.overrides
|
11
|
-
described_class.scheduled = {}
|
12
|
-
described_class.overrides = {}
|
13
|
-
block.call
|
14
|
-
ensure
|
15
|
-
described_class.scheduled = prev_sched
|
16
|
-
described_class.overrides = prev_ovr
|
17
|
-
Delayed::Job.delete_all
|
18
|
-
end
|
19
|
-
|
20
|
-
describe ".cron" do
|
21
|
-
let(:job_name) { "just a test" }
|
22
|
-
|
23
|
-
it "provides a tag by default for periodic jobs" do
|
24
|
-
described_class.cron job_name, "*/10 * * * *" do
|
25
|
-
# no-op
|
26
|
-
end
|
27
|
-
instance = described_class.scheduled[job_name]
|
28
|
-
expect(instance).not_to be_nil
|
29
|
-
expect(instance.enqueue_args[:singleton]).to eq("periodic: just a test")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
data/spec/delayed/server_spec.rb
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
require "delayed/server"
|
5
|
-
|
6
|
-
RSpec.describe Delayed::Server, sinatra: true do
|
7
|
-
include Rack::Test::Methods
|
8
|
-
|
9
|
-
@update = false
|
10
|
-
|
11
|
-
def app
|
12
|
-
described_class.new(update: @update)
|
13
|
-
end
|
14
|
-
|
15
|
-
def parsed_body
|
16
|
-
@parsed_body ||= JSON.parse(last_response.body)
|
17
|
-
end
|
18
|
-
|
19
|
-
before :all do
|
20
|
-
Delayed.select_backend(Delayed::Backend::ActiveRecord::Job)
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "get '/running'" do
|
24
|
-
before do
|
25
|
-
3.times do |i|
|
26
|
-
Delayed::Job.create!({
|
27
|
-
run_at: Time.zone.now,
|
28
|
-
locked_at: Time.zone.now,
|
29
|
-
locked_by: "dummy-runner-#{i}:${$$}"
|
30
|
-
})
|
31
|
-
end
|
32
|
-
get "/running"
|
33
|
-
end
|
34
|
-
|
35
|
-
it "must return a json object with the running job data in an array", aggregate_failures: true do
|
36
|
-
expect(last_response).to be_ok
|
37
|
-
expect(parsed_body["data"]).to be_an Array
|
38
|
-
expect(parsed_body["data"].size).to eq 3
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "get '/jobs'" do
|
43
|
-
let!(:job1) { Delayed::Job.enqueue(SimpleJob.new, strand: "strand-1") }
|
44
|
-
let!(:job2) { Delayed::Job.enqueue(SimpleJob.new, strand: "strand-2") }
|
45
|
-
let!(:job3) { Delayed::Job.enqueue(SimpleJob.new, strand: "strand-3") }
|
46
|
-
|
47
|
-
context "with the flavor param set to id" do
|
48
|
-
before do
|
49
|
-
get "/jobs?flavor=id&search_term=#{job2.id}"
|
50
|
-
end
|
51
|
-
|
52
|
-
it "must only return the job with the id specified in the search_term param" do
|
53
|
-
jobs = parsed_body["data"]
|
54
|
-
job_ids = jobs.map { |j| j["id"] }
|
55
|
-
expect(job_ids).to eq [job2.id]
|
56
|
-
end
|
57
|
-
|
58
|
-
it "must set recordsFiltered in the response to 1" do
|
59
|
-
expect(parsed_body["recordsFiltered"]).to eq 1
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "post '/bulk_update'" do
|
65
|
-
let!(:job1) { Delayed::Job.enqueue(SimpleJob.new, strand: "strand-1") }
|
66
|
-
let!(:job2) { Delayed::Job.enqueue(SimpleJob.new, strand: "strand-2") }
|
67
|
-
let!(:job3) { Delayed::Job.enqueue(SimpleJob.new, strand: "strand-3") }
|
68
|
-
|
69
|
-
context "with update enabled" do
|
70
|
-
before do
|
71
|
-
@update = true
|
72
|
-
post "/bulk_update", JSON.generate(action: "destroy", ids: [job1.id])
|
73
|
-
end
|
74
|
-
|
75
|
-
it "must remove job1" do
|
76
|
-
expect { Delayed::Job.find(job1.id) }.to raise_error(ActiveRecord::RecordNotFound)
|
77
|
-
expect(Delayed::Job.find(job2.id)).not_to be_nil
|
78
|
-
expect(Delayed::Job.find(job3.id)).not_to be_nil
|
79
|
-
end
|
80
|
-
|
81
|
-
it "must return ok" do
|
82
|
-
expect(last_response.ok?).to be true
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "with update disabled" do
|
87
|
-
before do
|
88
|
-
@update = false
|
89
|
-
post "/bulk_update", JSON.generate(action: "destroy", ids: [job1.id])
|
90
|
-
end
|
91
|
-
|
92
|
-
it "must not remove job1" do
|
93
|
-
expect(Delayed::Job.find(job1.id)).not_to be_nil
|
94
|
-
expect(Delayed::Job.find(job2.id)).not_to be_nil
|
95
|
-
expect(Delayed::Job.find(job3.id)).not_to be_nil
|
96
|
-
end
|
97
|
-
|
98
|
-
it "must return forbidden" do
|
99
|
-
expect(last_response.forbidden?).to be true
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
RSpec.describe Delayed::Settings do
|
6
|
-
let(:configfile) do
|
7
|
-
<<~YAML
|
8
|
-
default:
|
9
|
-
workers:
|
10
|
-
- queue: myqueue
|
11
|
-
workers: 2
|
12
|
-
- queue: secondqueue
|
13
|
-
max_priority: 7
|
14
|
-
max_attempts: 1
|
15
|
-
YAML
|
16
|
-
end
|
17
|
-
|
18
|
-
describe ".worker_config" do
|
19
|
-
it "merges each worker config with the top-level config" do
|
20
|
-
expect(File).to receive(:read).with("fname").and_return(configfile)
|
21
|
-
config = described_class.worker_config("fname")
|
22
|
-
expect(config[:workers]).to eq([
|
23
|
-
{ "queue" => "myqueue", "workers" => 2, "max_attempts" => 1 },
|
24
|
-
{ "queue" => "secondqueue", "max_priority" => 7, "max_attempts" => 1 }
|
25
|
-
])
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe ".apply_worker_config!" do
|
30
|
-
it "applies global settings from the given config" do
|
31
|
-
expect(described_class).to receive(:last_ditch_logfile=).with(true)
|
32
|
-
described_class.apply_worker_config!("last_ditch_logfile" => true)
|
33
|
-
end
|
34
|
-
|
35
|
-
it "merges in parent_process overrides to default config" do
|
36
|
-
described_class.apply_worker_config!("parent_process" => { "foo" => "bar" })
|
37
|
-
|
38
|
-
expect(described_class.parent_process).to include("foo" => "bar")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe ".parent_process_client_timeout=" do
|
43
|
-
it "must update the value in the parent_process settings hash" do
|
44
|
-
described_class.parent_process_client_timeout = 42
|
45
|
-
expect(described_class.parent_process["server_socket_timeout"]).to eq 42
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "spec_helper"
|
4
|
-
|
5
|
-
RSpec.describe Delayed::WorkQueue::InProcess do
|
6
|
-
before :all do
|
7
|
-
Delayed.select_backend(Delayed::Backend::ActiveRecord::Job)
|
8
|
-
end
|
9
|
-
|
10
|
-
after do
|
11
|
-
Delayed::Worker.lifecycle.reset!
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:worker_config) { { queue: "test", min_priority: 1, max_priority: 2 } }
|
15
|
-
let(:args) { ["worker_name", worker_config] }
|
16
|
-
|
17
|
-
it "triggers the lifecycle event around the pop" do
|
18
|
-
called = false
|
19
|
-
Delayed::Worker.lifecycle.around(:work_queue_pop) do |queue, &cb|
|
20
|
-
expect(queue).to eq(subject)
|
21
|
-
expect(Delayed::Job).to receive(:get_and_lock_next_available)
|
22
|
-
.with("worker_name", "test", 1, 2)
|
23
|
-
.and_return(:job)
|
24
|
-
called = true
|
25
|
-
cb.call(queue)
|
26
|
-
end
|
27
|
-
job = subject.get_and_lock_next_available(*args)
|
28
|
-
expect(job).to eq(:job)
|
29
|
-
expect(called).to eq(true)
|
30
|
-
end
|
31
|
-
end
|