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.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +4 -2
  3. data/db/migrate/20200825011002_add_strand_order_override.rb +2 -1
  4. data/db/migrate/20210809145804_add_n_strand_index.rb +2 -1
  5. data/db/migrate/20220328152900_add_failed_jobs_indicies.rb +12 -0
  6. data/db/migrate/20220519204546_add_requeued_job_id_to_failed_jobs.rb +7 -0
  7. data/lib/delayed/backend/active_record.rb +77 -7
  8. data/lib/delayed/backend/base.rb +28 -10
  9. data/lib/delayed/batch.rb +1 -1
  10. data/lib/delayed/cli.rb +3 -2
  11. data/lib/delayed/lifecycle.rb +9 -2
  12. data/lib/delayed/log_tailer.rb +2 -2
  13. data/lib/delayed/message_sending.rb +9 -6
  14. data/lib/delayed/performable_method.rb +22 -16
  15. data/lib/delayed/periodic.rb +2 -2
  16. data/lib/delayed/pool.rb +12 -2
  17. data/lib/delayed/server.rb +8 -2
  18. data/lib/delayed/settings.rb +5 -1
  19. data/lib/delayed/version.rb +1 -1
  20. data/lib/delayed/work_queue/parent_process/server.rb +7 -3
  21. data/lib/delayed/worker/health_check.rb +1 -1
  22. data/lib/delayed/worker/process_helper.rb +4 -4
  23. data/lib/delayed/worker.rb +22 -11
  24. metadata +18 -119
  25. data/spec/active_record_job_spec.rb +0 -294
  26. data/spec/delayed/cli_spec.rb +0 -25
  27. data/spec/delayed/daemon_spec.rb +0 -38
  28. data/spec/delayed/message_sending_spec.rb +0 -108
  29. data/spec/delayed/periodic_spec.rb +0 -32
  30. data/spec/delayed/server_spec.rb +0 -103
  31. data/spec/delayed/settings_spec.rb +0 -48
  32. data/spec/delayed/work_queue/in_process_spec.rb +0 -31
  33. data/spec/delayed/work_queue/parent_process/client_spec.rb +0 -87
  34. data/spec/delayed/work_queue/parent_process/server_spec.rb +0 -280
  35. data/spec/delayed/work_queue/parent_process_spec.rb +0 -60
  36. data/spec/delayed/worker/consul_health_check_spec.rb +0 -63
  37. data/spec/delayed/worker/health_check_spec.rb +0 -134
  38. data/spec/delayed/worker_spec.rb +0 -105
  39. data/spec/migrate/20140924140513_add_story_table.rb +0 -9
  40. data/spec/sample_jobs.rb +0 -79
  41. data/spec/shared/delayed_batch.rb +0 -105
  42. data/spec/shared/delayed_method.rb +0 -287
  43. data/spec/shared/performable_method.rb +0 -75
  44. data/spec/shared/shared_backend.rb +0 -1221
  45. data/spec/shared/testing.rb +0 -50
  46. data/spec/shared/worker.rb +0 -413
  47. data/spec/shared_jobs_specs.rb +0 -17
  48. data/spec/spec_helper.rb +0 -136
@@ -1,105 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../spec_helper"
4
-
5
- describe Delayed::Worker do
6
- subject { described_class.new(worker_config.dup) }
7
-
8
- let(:worker_config) do
9
- {
10
- queue: "test", min_priority: 1, max_priority: 2, stuff: "stuff"
11
- }.freeze
12
- end
13
- let(:job_attrs) do
14
- {
15
- id: 42, name: "testjob", full_name: "testfullname", :last_error= => nil,
16
- attempts: 1, reschedule: nil, :expired? => false,
17
- payload_object: {}, priority: 25
18
- }.freeze
19
- end
20
-
21
- after { described_class.lifecycle.reset! }
22
-
23
- describe "#perform" do
24
- it "fires off an error callback when a job raises an exception" do
25
- fired = false
26
- described_class.lifecycle.before(:error) { |_worker, _exception| fired = true }
27
- job = double(job_attrs)
28
- output_count = subject.perform(job)
29
- expect(fired).to be_truthy
30
- expect(output_count).to eq(1)
31
- end
32
-
33
- it "uses the retry callback for a retriable exception" do
34
- error_fired = retry_fired = false
35
- described_class.lifecycle.before(:error) { |_worker, _exception| error_fired = true }
36
- described_class.lifecycle.before(:retry) { |_worker, _exception| retry_fired = true }
37
- job = Delayed::Job.new(payload_object: {}, priority: 25, strand: "test_jobs", max_attempts: 3)
38
- expect(job).to receive(:invoke_job) do
39
- raise Delayed::RetriableError, "that's all this job does"
40
- end
41
- output_count = subject.perform(job)
42
- expect(error_fired).to be_falsey
43
- expect(retry_fired).to be_truthy
44
- expect(output_count).to eq(1)
45
- end
46
-
47
- it "reloads Rails classes (never more than once)" do
48
- fake_application = double("Rails.application",
49
- config: double("Rails.application.config",
50
- cache_classes: false,
51
- reload_classes_only_on_change: false),
52
- reloader: double)
53
-
54
- allow(Rails).to receive(:application).and_return(fake_application)
55
- if Rails::VERSION::MAJOR >= 5
56
- expect(Rails.application.reloader).to receive(:reload!).once
57
- else
58
- expect(ActionDispatch::Reloader).to receive(:prepare!).once
59
- expect(ActionDispatch::Reloader).to receive(:cleanup!).once
60
- end
61
- job = double(job_attrs)
62
-
63
- # Create extra workers to make sure we don't reload multiple times
64
- described_class.new(worker_config.dup)
65
- described_class.new(worker_config.dup)
66
-
67
- subject.perform(job)
68
- end
69
- end
70
-
71
- describe "#log_job" do
72
- around do |block|
73
- prev_logger = Delayed::Settings.job_detailed_log_format
74
- block.call
75
- Delayed::Settings.job_detailed_log_format = prev_logger
76
- end
77
-
78
- it "has a reasonable default format" do
79
- payload = double(perform: nil)
80
- job = Delayed::Job.new(payload_object: payload, priority: 25, strand: "test_jobs")
81
- short_log_format = subject.log_job(job, :short)
82
- expect(short_log_format).to eq("RSpec::Mocks::Double")
83
- long_format = subject.log_job(job, :long)
84
- expect(long_format).to eq("RSpec::Mocks::Double {\"priority\":25,\"attempts\":0,\"created_at\":null,\"tag\":\"RSpec::Mocks::Double#perform\",\"max_attempts\":null,\"strand\":\"test_jobs\",\"source\":null}") # rubocop:disable Layout/LineLength
85
- end
86
-
87
- it "logging format can be changed with settings" do
88
- Delayed::Settings.job_detailed_log_format = ->(job) { "override format #{job.strand}" }
89
- payload = double(perform: nil)
90
- job = Delayed::Job.new(payload_object: payload, priority: 25, strand: "test_jobs")
91
- short_log_format = subject.log_job(job, :short)
92
- expect(short_log_format).to eq("RSpec::Mocks::Double")
93
- long_format = subject.log_job(job, :long)
94
- expect(long_format).to eq("RSpec::Mocks::Double override format test_jobs")
95
- end
96
- end
97
-
98
- describe "#run" do
99
- it "passes extra config options through to the WorkQueue" do
100
- expect(subject.work_queue).to receive(:get_and_lock_next_available)
101
- .with(subject.name, worker_config).and_return(nil)
102
- subject.run
103
- end
104
- end
105
- end
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class AddStoryTable < ActiveRecord::Migration[4.2]
4
- def change
5
- create_table :stories do |table|
6
- table.string :text
7
- end
8
- end
9
- end
data/spec/sample_jobs.rb DELETED
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class SimpleJob
4
- class << self
5
- attr_accessor :runs
6
- end
7
-
8
- self.runs = 0
9
-
10
- def perform
11
- self.class.runs += 1
12
- end
13
- end
14
-
15
- class ErrorJob
16
- class << self
17
- attr_accessor :runs, :last_error, :failure_runs, :permanent_failure_runs
18
- end
19
-
20
- self.runs = 0
21
- def perform
22
- raise "did not work"
23
- end
24
-
25
- self.last_error = nil
26
- self.failure_runs = 0
27
- def on_failure(error)
28
- self.class.last_error = error
29
- self.class.failure_runs += 1
30
- end
31
-
32
- self.permanent_failure_runs = 0
33
- def on_permanent_failure(error)
34
- self.class.last_error = error
35
- self.class.permanent_failure_runs += 1
36
- end
37
- end
38
-
39
- class UnlockJob
40
- attr_accessor :times_to_unlock
41
-
42
- def initialize(times_to_unlock)
43
- @times_to_unlock = times_to_unlock
44
- end
45
-
46
- def perform
47
- raise SystemExit, "raising to trigger on_failure"
48
- end
49
-
50
- def on_failure(_error)
51
- times_to_unlock -= 1
52
- :unlock if times_to_unlock <= 0
53
- end
54
- end
55
-
56
- class LongRunningJob
57
- def perform
58
- sleep 250
59
- end
60
- end
61
-
62
- module M
63
- class ModuleJob
64
- class << self
65
- attr_accessor :runs
66
- end
67
-
68
- cattr_accessor :runs
69
- self.runs = 0
70
- def perform
71
- self.class.runs += 1
72
- end
73
- end
74
- end
75
-
76
- class DeserializeErrorJob < SimpleJob; end
77
- Psych.add_domain_type("ruby/object", "DeserializeErrorJob") do |_type, _val|
78
- raise "error deserializing"
79
- end
@@ -1,105 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- shared_examples_for "Delayed::Batch" do
4
- context "batching" do
5
- it "batches up all deferrable delayed methods" do
6
- later = 1.hour.from_now
7
- Delayed::Batch.serial_batch do
8
- expect("string".delay(ignore_transaction: true).size).to be true
9
- # won't be batched, it'll get its own job
10
- expect("string".delay(run_at: later, ignore_transaction: true).reverse).to be_truthy
11
- expect("string".delay(ignore_transaction: true).gsub(/./, "!")).to be_truthy
12
- end
13
- batch_jobs = Delayed::Job.find_available(5)
14
- regular_jobs = Delayed::Job.list_jobs(:future, 5)
15
- expect(regular_jobs.size).to eq(1)
16
- expect(regular_jobs.first.batch?).to eq(false)
17
- expect(batch_jobs.size).to eq(1)
18
- batch_job = batch_jobs.first
19
- expect(batch_job.batch?).to eq(true)
20
- expect(batch_job.payload_object.mode).to eq(:serial)
21
- expect(batch_job.payload_object.jobs.map do |j|
22
- [j.payload_object.object, j.payload_object.method, j.payload_object.args]
23
- end).to eq([
24
- [
25
- "string", :size, []
26
- ],
27
- [
28
- "string", :gsub, [
29
- /./, "!"
30
- ]
31
- ]
32
- ])
33
- end
34
-
35
- it "does not let you invoke it directly" do
36
- Delayed::Batch.serial_batch do
37
- expect("string".delay(ignore_transaction: true).size).to be true
38
- expect("string".delay(ignore_transaction: true).gsub(/./, "!")).to be true
39
- end
40
- expect(Delayed::Job.jobs_count(:current)).to eq(1)
41
- job = Delayed::Job.find_available(1).first
42
- expect { job.invoke_job }.to raise_error(RuntimeError)
43
- end
44
-
45
- it "creates valid jobs" do
46
- Delayed::Batch.serial_batch do
47
- expect("string".delay(ignore_transaction: true).size).to be true
48
- expect("string".delay(ignore_transaction: true).gsub(/./, "!")).to be true
49
- end
50
- expect(Delayed::Job.jobs_count(:current)).to eq(1)
51
-
52
- batch_job = Delayed::Job.find_available(1).first
53
- expect(batch_job.batch?).to eq(true)
54
- jobs = batch_job.payload_object.jobs
55
- expect(jobs.size).to eq(2)
56
- expect(jobs[0]).to be_new_record
57
- expect(jobs[0].payload_object.class).to eq(Delayed::PerformableMethod)
58
- expect(jobs[0].payload_object.method).to eq(:size)
59
- expect(jobs[0].payload_object.args).to eq([])
60
- expect(jobs[0].payload_object.perform).to eq(6)
61
- expect(jobs[1]).to be_new_record
62
- expect(jobs[1].payload_object.class).to eq(Delayed::PerformableMethod)
63
- expect(jobs[1].payload_object.method).to eq(:gsub)
64
- expect(jobs[1].payload_object.args).to eq([/./, "!"])
65
- expect(jobs[1].payload_object.perform).to eq("!!!!!!")
66
- end
67
-
68
- it "creates a different batch for each priority" do
69
- Delayed::Batch.serial_batch do
70
- expect("string".delay(priority: Delayed::LOW_PRIORITY, ignore_transaction: true).size).to be true
71
- expect("string".delay(ignore_transaction: true).gsub(/./, "!")).to be true
72
- end
73
- expect(Delayed::Job.jobs_count(:current)).to eq(2)
74
- end
75
-
76
- it "uses the given priority for all, if specified" do
77
- Delayed::Batch.serial_batch(priority: 11) do
78
- expect("string".delay(priority: 20, ignore_transaction: true).size).to be true
79
- expect("string".delay(priority: 15, ignore_transaction: true).gsub(/./, "!")).to be true
80
- end
81
- expect(Delayed::Job.jobs_count(:current)).to eq(1)
82
- expect(Delayed::Job.find_available(1).first.priority).to eq(11)
83
- end
84
-
85
- it "justs create the job, if there's only one in the batch" do
86
- Delayed::Batch.serial_batch(priority: 11) do
87
- expect("string".delay(ignore_transaction: true).size).to be true
88
- end
89
- expect(Delayed::Job.jobs_count(:current)).to eq(1)
90
- expect(Delayed::Job.find_available(1).first.tag).to eq("String#size")
91
- expect(Delayed::Job.find_available(1).first.priority).to eq(11)
92
- end
93
-
94
- it "lists a job only once when the same call is made multiple times" do
95
- Delayed::Batch.serial_batch(priority: 11) do
96
- "string".delay(ignore_transaction: true).size
97
- "string".delay(ignore_transaction: true).gsub(/./, "!")
98
- "string".delay(ignore_transaction: true).size
99
- end
100
- batch_job = Delayed::Job.find_available(1).first
101
- jobs = batch_job.payload_object.jobs
102
- expect(jobs.size).to eq(2)
103
- end
104
- end
105
- end
@@ -1,287 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module UnlessInJob
4
- class << self
5
- attr_accessor :runs
6
-
7
- def run
8
- self.runs += 1
9
- end
10
-
11
- def run_later
12
- delay(synchronous: Delayed::Job.in_delayed_job?).run
13
- end
14
- end
15
- end
16
-
17
- shared_examples_for "random ruby objects" do
18
- def set_queue(name) # rubocop:disable Naming/AccessorMethodName
19
- old_name = Delayed::Settings.queue
20
- Delayed::Settings.queue = name
21
- ensure
22
- Delayed::Settings.queue = old_name
23
- end
24
-
25
- it "respond_toes :delay method" do
26
- Object.new.respond_to?(:delay)
27
- end
28
-
29
- it "raises a ArgumentError if delay is called but the target method doesn't exist" do
30
- expect { Object.new.delay.method_that_deos_not_exist }.to raise_error(NoMethodError)
31
- end
32
-
33
- it "adds a new entry to the job table when delay is called on it" do
34
- expect { Object.new.delay.to_s }.to change { Delayed::Job.jobs_count(:current) }.by(1)
35
- end
36
-
37
- it "adds a new entry to the job table when delay is called on it with a queue" do
38
- expect { Object.new.delay(queue: "testqueue").to_s }.to change {
39
- Delayed::Job.jobs_count(:current, "testqueue")
40
- }.by(1)
41
- end
42
-
43
- it "adds a new entry to the job table when delay is called on the class" do
44
- expect { Object.delay.to_s }.to change { Delayed::Job.jobs_count(:current) }.by(1)
45
- end
46
-
47
- it "adds a new entry to the job table when delay is called on the class with a queue" do
48
- expect { Object.delay(queue: "testqueue").to_s }.to change { Delayed::Job.jobs_count(:current, "testqueue") }.by(1)
49
- end
50
-
51
- context "class methods" do
52
- context "handle_asynchronously" do
53
- it "works with default_async" do
54
- klass = Class.new do
55
- attr_reader :ran
56
-
57
- def test_method
58
- @ran = true
59
- end
60
- handle_asynchronously :test_method
61
- end
62
- obj = klass.new
63
- expect { obj.test_method }.to change { Delayed::Job.jobs_count(:current) }.by(1)
64
- expect(obj.ran).to be_falsey
65
- expect { obj.test_method(synchronous: true) }.not_to(change { Delayed::Job.jobs_count(:current) })
66
- expect(obj.ran).to be true
67
- end
68
-
69
- it "must work with enqueue args that are lambdas" do
70
- klass = Class.new do
71
- attr_reader :ran
72
-
73
- def test_method
74
- @ran = true
75
- end
76
- handle_asynchronously :test_method, singleton: ->(obj) { "foobar:#{obj.object_id}" }
77
- end
78
-
79
- obj = klass.new
80
- expect { obj.test_method }.to change { Delayed::Job.jobs_count(:current) }.by(1)
81
- end
82
-
83
- it "must work with kwargs in the original method" do
84
- klass = Class.new do
85
- attr_reader :run
86
-
87
- def test_method(my_kwarg: nil)
88
- @run = my_kwarg
89
- end
90
- handle_asynchronously :test_method
91
-
92
- def other_test(arg)
93
- @foo = arg
94
- end
95
- handle_asynchronously :other_test
96
- end
97
-
98
- obj = klass.new
99
- obj.test_method(my_kwarg: "foo", synchronous: true)
100
- expect(obj.run).to eq "foo"
101
- end
102
-
103
- it "sends along enqueue args and args" do
104
- klass = Class.new do
105
- attr_accessor :ran
106
-
107
- def test_method(*args)
108
- @ran = args
109
- end
110
- handle_asynchronously(:test_method, enqueue_arg1: :thing)
111
- end
112
- obj = klass.new
113
- method = double
114
-
115
- expect(Delayed::PerformableMethod).to receive(:new)
116
- .with(obj,
117
- :test_method,
118
- args: [1, 2, 3],
119
- kwargs: { synchronous: true },
120
- on_failure: nil,
121
- on_permanent_failure: nil,
122
- sender: obj)
123
- .and_return(method)
124
- expect(Delayed::Job).to receive(:enqueue).with(method, enqueue_arg1: :thing)
125
- obj.test_method(1, 2, 3)
126
-
127
- expect(Delayed::PerformableMethod).to receive(:new)
128
- .with(obj,
129
- :test_method,
130
- args: [4],
131
- kwargs: { synchronous: true },
132
- on_failure: nil,
133
- on_permanent_failure: nil,
134
- sender: obj)
135
- .and_return(method)
136
- expect(Delayed::Job).to receive(:enqueue).with(method, enqueue_arg1: :thing)
137
- obj.test_method(4)
138
-
139
- expect(obj.ran).to be_nil
140
- obj.test_method(7, synchronous: true)
141
- expect(obj.ran).to eq([7])
142
- obj.ran = nil
143
- expect(obj.ran).to eq(nil)
144
- obj.test_method(8, 9, synchronous: true)
145
- expect(obj.ran).to eq([8, 9])
146
- end
147
-
148
- it "handles punctuation correctly" do
149
- klass = Class.new do
150
- attr_reader :ran
151
-
152
- def test_method?
153
- @ran = true
154
- end
155
- handle_asynchronously :test_method?
156
- end
157
- obj = klass.new
158
- expect { obj.test_method? }.to change { Delayed::Job.jobs_count(:current) }.by(1)
159
- expect(obj.ran).to be_falsey
160
- expect { obj.test_method?(synchronous: true) }.not_to(change { Delayed::Job.jobs_count(:current) })
161
- expect(obj.ran).to be true
162
- end
163
-
164
- it "handles assignment punctuation correctly" do
165
- klass = Class.new do
166
- attr_reader :ran
167
-
168
- def test_method=(val)
169
- @ran = val
170
- end
171
- handle_asynchronously :test_method=
172
- end
173
- obj = klass.new
174
- expect { obj.test_method = 3 }.to change { Delayed::Job.jobs_count(:current) }.by(1)
175
- expect(obj.ran).to be_nil
176
- expect { obj.send(:test_method=, 5, synchronous: true) }.not_to(change { Delayed::Job.jobs_count(:current) })
177
- expect(obj.ran).to eq(5)
178
- end
179
-
180
- it "correctlies sort out method accessibility" do
181
- klass1 = Class.new do
182
- def test_method; end
183
- handle_asynchronously :test_method
184
- end
185
-
186
- klass2 = Class.new do
187
- protected
188
-
189
- def test_method; end
190
- handle_asynchronously :test_method
191
- end
192
-
193
- klass3 = Class.new do
194
- private
195
-
196
- def test_method; end
197
- handle_asynchronously :test_method
198
- end
199
-
200
- expect(klass1.public_method_defined?(:test_method)).to be true
201
- expect(klass2.protected_method_defined?(:test_method)).to be true
202
- expect(klass3.private_method_defined?(:test_method)).to be true
203
- end
204
- end
205
- end
206
-
207
- it "calls send later on methods which are wrapped with handle_asynchronously" do
208
- story = Story.create text: "Once upon..."
209
-
210
- expect { story.whatever(1, 5) }.to change { Delayed::Job.jobs_count(:current) }.by(1)
211
-
212
- job = Delayed::Job.list_jobs(:current, 1).first
213
- expect(job.payload_object.class).to eq(Delayed::PerformableMethod)
214
- expect(job.payload_object.method).to eq(:whatever)
215
- expect(job.payload_object.args).to eq([1, 5])
216
- expect(job.payload_object.kwargs).to eq({ synchronous: true })
217
- expect(job.payload_object.perform).to eq("Once upon...")
218
- end
219
-
220
- context "delay" do
221
- it "uses the default queue if there is one" do
222
- set_queue("testqueue") do
223
- "string".delay.reverse
224
- job = Delayed::Job.list_jobs(:current, 1).first
225
- expect(job.queue).to eq("testqueue")
226
-
227
- "string".delay(queue: nil).reverse
228
- job2 = Delayed::Job.list_jobs(:current, 2).last
229
- expect(job2.queue).to eq("testqueue")
230
- end
231
- end
232
-
233
- it "requires a queue" do
234
- expect { set_queue(nil) }.to raise_error(ArgumentError)
235
- end
236
- end
237
-
238
- context "delay with run_at" do
239
- it "queues a new job" do
240
- expect do
241
- "string".delay(run_at: 1.hour.from_now).length
242
- end.to change { Delayed::Job.jobs_count(:future) }.by(1)
243
- end
244
-
245
- it "schedules the job in the future" do
246
- time = 1.hour.from_now
247
- "string".delay(run_at: time).length
248
- job = Delayed::Job.list_jobs(:future, 1).first
249
- expect(job.run_at.to_i).to eq(time.to_i)
250
- end
251
-
252
- it "stores payload as PerformableMethod" do
253
- "string".delay(run_at: 1.hour.from_now).count("r")
254
- job = Delayed::Job.list_jobs(:future, 1).first
255
- expect(job.payload_object.class).to eq(Delayed::PerformableMethod)
256
- expect(job.payload_object.method).to eq(:count)
257
- expect(job.payload_object.args).to eq(["r"])
258
- expect(job.payload_object.perform).to eq(1)
259
- end
260
-
261
- it "uses the default queue if there is one" do
262
- set_queue("testqueue") do
263
- "string".delay(run_at: 1.hour.from_now).reverse
264
- job = Delayed::Job.list_jobs(:current, 1).first
265
- expect(job.queue).to eq("testqueue")
266
- end
267
- end
268
- end
269
-
270
- describe "delay with synchronous argument" do
271
- before do
272
- UnlessInJob.runs = 0
273
- end
274
-
275
- it "performs immediately if in job" do
276
- UnlessInJob.delay.run_later
277
- job = Delayed::Job.list_jobs(:current, 1).first
278
- job.invoke_job
279
- expect(UnlessInJob.runs).to eq(1)
280
- end
281
-
282
- it "queues up for later if not in job" do
283
- UnlessInJob.run_later
284
- expect(UnlessInJob.runs).to eq(0)
285
- end
286
- end
287
- end
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- shared_examples_for "Delayed::PerformableMethod" do
4
- it "does not ignore ActiveRecord::RecordNotFound errors because they are not always permanent" do
5
- story = Story.create text: "Once upon..."
6
- p = Delayed::PerformableMethod.new(story, :tell)
7
- story.destroy
8
- expect { YAML.load(p.to_yaml) }.to raise_error(Delayed::Backend::RecordNotFound)
9
- end
10
-
11
- it "stores the object using native YAML even if its an active record" do
12
- story = Story.create text: "Once upon..."
13
- p = Delayed::PerformableMethod.new(story, :tell)
14
- expect(p.class).to eq(Delayed::PerformableMethod)
15
- expect(p.object).to eq(story)
16
- expect(p.method).to eq(:tell)
17
- expect(p.args).to eq([])
18
- expect(p.perform).to eq("Once upon...")
19
- end
20
-
21
- it "allows class methods to be called on ActiveRecord models" do
22
- Story.create!(text: "Once upon a...")
23
- p = Delayed::PerformableMethod.new(Story, :count)
24
- expect { expect(p.send(:perform)).to be 1 }.not_to raise_error
25
- end
26
-
27
- it "allows class methods to be called" do
28
- p = Delayed::PerformableMethod.new(StoryReader, :reverse, args: ["ohai"])
29
- expect { expect(p.send(:perform)).to eq("iaho") }.not_to raise_error
30
- end
31
-
32
- it "allows module methods to be called" do
33
- p = Delayed::PerformableMethod.new(MyReverser, :reverse, args: ["ohai"])
34
- expect { expect(p.send(:perform)).to eq("iaho") }.not_to raise_error
35
- end
36
-
37
- it "stores arguments as native YAML if they are active record objects" do
38
- story = Story.create text: "Once upon..."
39
- reader = StoryReader.new
40
- p = Delayed::PerformableMethod.new(reader, :read, args: [story])
41
- expect(p.class).to eq(Delayed::PerformableMethod)
42
- expect(p.method).to eq(:read)
43
- expect(p.args).to eq([story])
44
- expect(p.perform).to eq("Epilog: Once upon...")
45
- end
46
-
47
- it "deeplies de-AR-ize arguments in full name" do
48
- story = Story.create text: "Once upon..."
49
- reader = StoryReader.new
50
- p = Delayed::PerformableMethod.new(reader, :read, args: [["arg1", story, { [:key, 1] => story }]])
51
- expect(p.full_name).to eq(
52
- "StoryReader#read([\"arg1\", Story.find(#{story.id}), {[:key, 1] => Story.find(#{story.id})}])"
53
- )
54
- end
55
-
56
- it "calls the on_failure callback" do
57
- story = Story.create text: "wat"
58
- p = Delayed::PerformableMethod.new(story, :tell, on_failure: :text=)
59
- p.send(:on_failure, "fail")
60
- expect(story.text).to eq("fail")
61
- end
62
-
63
- it "calls the on_permanent_failure callback" do
64
- story = Story.create text: "wat"
65
- p = Delayed::PerformableMethod.new(story, :tell, on_permanent_failure: :text=)
66
- p.send(:on_permanent_failure, "fail_frd")
67
- expect(story.text).to eq("fail_frd")
68
- end
69
-
70
- it "can still generate a name with no kwargs" do
71
- story = Story.create text: "wat"
72
- p = Delayed::PerformableMethod.new(story, :tell, kwargs: nil)
73
- expect(p.full_name).to eq("Story.find(#{story.id}).tell()")
74
- end
75
- end