inst-jobs 3.1.2 → 3.1.3

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: 95bdbd537405c6325f378bed05570a3149053ba8a2e290893010c590df72ea9a
4
- data.tar.gz: 6f0d577f1fba37bb01e3e0a4ec05b600e65ebb77d001e29e38b479f6facde73b
3
+ metadata.gz: dfa0a9108f1f1440f7e5a1e85751f9b359c87a07c96ef915e957fd7273f03e70
4
+ data.tar.gz: '081a50c77e4cab9add18ab344778d9eed42ca67d9c20a8e8c2fff9a47c0984f9'
5
5
  SHA512:
6
- metadata.gz: 38392cab25180d44f40960ffb15b2dd3241bd739980b9d0962b93020a809497bb1a9022caf7a05f4ba40f4cc3792281f03468946c33a1fc62891dec3b411f7cf
7
- data.tar.gz: cbea2ab6e762a876994179ac1c9ffd414ea2ec13905931b2cddb087d816664e8b682ecf8f9406726d8f80a0867b8e44bc1331b6e0e73de3415b4ab31090d1ee9
6
+ metadata.gz: 82752f8b1dcade468721c7a5e22680d875a799476380b0351b8eda4346aa914032efbd89c401d99d2de23b84c09c559d3a825c44e682b83ec3c6f3ce658e7d6e
7
+ data.tar.gz: 5db1c149af1f02f111998096dfe6207f622aa13481b8b6c8170153968c2e90c1319783932ea8bea0e31feb8589589f4c15c0dafda3205bfec61e26cf16c5caa4
@@ -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 { |c| c.call(*args, result: result) }
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Delayed
4
- VERSION = "3.1.2"
4
+ VERSION = "3.1.3"
5
5
  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: 3.1.2
4
+ version: 3.1.3
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-05-25 00:00:00.000000000 Z
13
+ date: 2022-05-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
@@ -500,30 +500,6 @@ 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:
@@ -547,28 +523,4 @@ rubygems_version: 3.1.6
547
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
@@ -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
@@ -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