inst-jobs 3.0.8 → 3.1.11

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 +63 -6
  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 +8 -5
  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 +8 -8
  24. metadata +16 -89
  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,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class TestingWorker
4
- cattr_accessor :runs
5
-
6
- def self.run
7
- self.runs += 1
8
- end
9
- end
10
-
11
- shared_examples_for "Delayed::Testing" do
12
- before do
13
- TestingWorker.runs = 0
14
- end
15
-
16
- describe ".run_job" do
17
- it "runs a single queued job" do
18
- job = TestingWorker.delay(ignore_transaction: true).run
19
- Delayed::Testing.run_job(job)
20
- expect(TestingWorker.runs).to eq 1
21
- end
22
- end
23
-
24
- describe ".drain" do
25
- it "runs all queued jobs" do
26
- 3.times { TestingWorker.delay.run }
27
- YAML.dump(TestingWorker)
28
- Delayed::Testing.drain
29
- expect(TestingWorker.runs).to eq 3
30
- end
31
- end
32
-
33
- describe "track_created" do
34
- it "returns the list of jobs created in the block" do
35
- 3.times { TestingWorker.delay.run }
36
- jobs = Delayed::Testing.track_created { 2.times { TestingWorker.delay.run } }
37
- expect(jobs.size).to eq 2
38
- expect(jobs.first.tag).to eq "TestingWorker.run"
39
- end
40
- end
41
-
42
- describe "clear_all!" do
43
- it "deletes all queued jobs" do
44
- 3.times { TestingWorker.delay.run }
45
- Delayed::Testing.clear_all!
46
- Delayed::Testing.drain
47
- expect(TestingWorker.runs).to eq 0
48
- end
49
- end
50
- end
@@ -1,413 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class TestPlugin < ::Delayed::Plugin
4
- cattr_accessor :runs
5
- self.runs = 0
6
- callbacks do |lifecycle|
7
- lifecycle.around(:invoke_job) do |job, *args, &block|
8
- TestPlugin.runs += 1
9
- block.call(job, *args)
10
- end
11
- end
12
- end
13
-
14
- shared_examples_for "Delayed::Worker" do
15
- def job_create(opts = {})
16
- Delayed::Job.create({ payload_object: SimpleJob.new, queue: Delayed::Settings.queue }.merge(opts))
17
- end
18
-
19
- def worker_create(opts = {})
20
- Delayed::Worker.new(opts.merge(max_priority: nil, min_priority: nil, quiet: true))
21
- end
22
-
23
- before do
24
- @worker = worker_create
25
- SimpleJob.runs = 0
26
- Delayed::Worker.on_max_failures = nil
27
- Delayed::Settings.sleep_delay = -> { 0.01 }
28
- end
29
-
30
- after do
31
- Delayed::Settings.sleep_delay = 2.0
32
- end
33
-
34
- describe "running a job" do
35
- it "does not fail when running a job with a % in the name" do
36
- @job = "Some % Name here".delay(ignore_transaction: true).start_with?("Some % Name")
37
- @worker.perform(@job)
38
- end
39
- end
40
-
41
- describe "running a batch" do
42
- context "serially" do
43
- before do
44
- @runs = 0
45
- Delayed::Worker.lifecycle.after(:perform) { @runs += 1 }
46
- end
47
-
48
- after do
49
- Delayed::Worker.lifecycle.reset!
50
- end
51
-
52
- it "runs each job in order" do
53
- bar = +"bar"
54
- expect(bar).to receive(:scan).with("b").ordered
55
- expect(bar).to receive(:scan).with("a").ordered
56
- expect(bar).to receive(:scan).with("r").ordered
57
- batch = Delayed::Batch::PerformableBatch.new(:serial, [
58
- { payload_object: Delayed::PerformableMethod.new(bar, :scan,
59
- args: ["b"]) },
60
- { payload_object: Delayed::PerformableMethod.new(bar, :scan,
61
- args: ["a"]) },
62
- { payload_object: Delayed::PerformableMethod.new(bar, :scan,
63
- args: ["r"]) }
64
- ])
65
-
66
- batch_job = Delayed::Job.create payload_object: batch
67
- expect(@worker.perform(batch_job)).to eq(3)
68
- expect(@runs).to be 4 # batch, plus all jobs
69
- end
70
-
71
- it "succeeds regardless of the success/failure of its component jobs" do
72
- change_setting(Delayed::Settings, :max_attempts, 2) do
73
- batch = Delayed::Batch::PerformableBatch.new(:serial, [
74
- { payload_object: Delayed::PerformableMethod.new("foo",
75
- :reverse) },
76
- { payload_object: Delayed::PerformableMethod.new(1, :/,
77
- args: [0]) },
78
- { payload_object: Delayed::PerformableMethod.new("bar", :scan,
79
- args: ["r"]) }
80
- ])
81
- batch_job = Delayed::Job.create payload_object: batch
82
-
83
- expect(@worker.perform(batch_job)).to eq(3)
84
- expect(@runs).to be 3 # batch, plus two successful jobs
85
-
86
- to_retry = Delayed::Job.list_jobs(:future, 100)
87
- expect(to_retry.size).to be 1
88
- expect(to_retry[0].payload_object.method).to be :/
89
- expect(to_retry[0].last_error).to match(/divided by 0/)
90
- expect(to_retry[0].attempts).to eq(1)
91
- end
92
- end
93
-
94
- it "retries a failed individual job" do
95
- batch = Delayed::Batch::PerformableBatch.new(:serial, [
96
- { payload_object: Delayed::PerformableMethod.new(1,
97
- :/,
98
- args: [0]) }
99
- ])
100
- batch_job = Delayed::Job.create payload_object: batch
101
-
102
- expect_any_instance_of(Delayed::Job).to receive(:reschedule).once
103
- expect(@worker.perform(batch_job)).to eq(1)
104
- expect(@runs).to be 1 # just the batch
105
- end
106
- end
107
- end
108
-
109
- context "worker prioritization" do
110
- before do
111
- @worker = Delayed::Worker.new(max_priority: 5, min_priority: 2, quiet: true)
112
- end
113
-
114
- it "onlies run jobs that are >= min_priority" do
115
- expect(SimpleJob.runs).to eq(0)
116
-
117
- job_create(priority: 1)
118
- job_create(priority: 3)
119
- @worker.run
120
-
121
- expect(SimpleJob.runs).to eq(1)
122
- end
123
-
124
- it "onlies run jobs that are <= max_priority" do
125
- expect(SimpleJob.runs).to eq(0)
126
-
127
- job_create(priority: 10)
128
- job_create(priority: 4)
129
-
130
- @worker.run
131
-
132
- expect(SimpleJob.runs).to eq(1)
133
- end
134
- end
135
-
136
- context "while running with locked jobs" do
137
- it "does not run jobs locked by another worker" do
138
- job_create(locked_by: "other_worker", locked_at: (Delayed::Job.db_time_now - 1.minute))
139
- expect { @worker.run }.not_to(change(SimpleJob, :runs))
140
- end
141
-
142
- it "runs open jobs" do
143
- job_create
144
- expect { @worker.run }.to change(SimpleJob, :runs).from(0).to(1)
145
- end
146
- end
147
-
148
- describe "failed jobs" do
149
- before do
150
- # reset defaults
151
- Delayed::Settings.max_attempts = 25
152
- @job = Delayed::Job.enqueue ErrorJob.new
153
- end
154
-
155
- it "records last_error when destroy_failed_jobs = false, max_attempts = 1" do
156
- Delayed::Worker.on_max_failures = proc { false }
157
- @job.max_attempts = 1
158
- @job.save!
159
- expect(job = Delayed::Job.get_and_lock_next_available("w1")).to eq(@job)
160
- @worker.perform(job)
161
- old_id = @job.id
162
- @job = Delayed::Job.list_jobs(:failed, 1).first
163
- expect(@job.original_job_id).to eq(old_id)
164
- expect(@job.last_error).to match(/did not work/)
165
- expect(@job.last_error).to match(%r{shared/worker.rb})
166
- expect(@job.attempts).to eq(1)
167
- expect(@job.failed_at).not_to be_nil
168
- expect(@job.run_at).to be > Delayed::Job.db_time_now - 10.minutes
169
- expect(@job.run_at).to be < Delayed::Job.db_time_now + 10.minutes
170
- # job stays locked after failing, for record keeping of time/worker
171
- expect(@job).to be_locked
172
-
173
- expect(Delayed::Job.find_available(100, @job.queue)).to eq([])
174
- end
175
-
176
- it "re-schedules jobs after failing" do
177
- @worker.perform(@job)
178
- @job = Delayed::Job.find(@job.id)
179
- expect(@job.last_error).to match(/did not work/)
180
- expect(@job.last_error).to match(/sample_jobs.rb:22:in `perform'/)
181
- expect(@job.attempts).to eq(1)
182
- expect(@job.run_at).to be > Delayed::Job.db_time_now - 10.minutes
183
- expect(@job.run_at).to be < Delayed::Job.db_time_now + 10.minutes
184
- end
185
-
186
- it "accepts :unlock return value from on_failure during reschedule and unlock the job" do
187
- expect_any_instance_of(Delayed::Job).to receive(:unlock).once
188
- @job = Delayed::Job.enqueue(UnlockJob.new(1))
189
- @worker.perform(@job)
190
- end
191
-
192
- it "notifies jobs on failure" do
193
- ErrorJob.failure_runs = 0
194
- @worker.perform(@job)
195
- expect(ErrorJob.failure_runs).to eq(1)
196
- end
197
-
198
- it "notifies jobs on permanent failure" do
199
- (Delayed::Settings.max_attempts - 1).times { @job.reschedule }
200
- ErrorJob.permanent_failure_runs = 0
201
- @worker.perform(@job)
202
- expect(ErrorJob.permanent_failure_runs).to eq(1)
203
- end
204
- end
205
-
206
- context "reschedule" do
207
- before do
208
- @job = Delayed::Job.create payload_object: SimpleJob.new
209
- end
210
-
211
- context "and we want to destroy jobs" do
212
- it "is destroyed if it failed more than Settings.max_attempts times" do
213
- expect(@job).to receive(:destroy)
214
- Delayed::Settings.max_attempts.times { @job.reschedule }
215
- end
216
-
217
- it "is not destroyed if failed fewer than Settings.max_attempts times" do
218
- expect(@job).not_to receive(:destroy)
219
- (Delayed::Settings.max_attempts - 1).times { @job.reschedule }
220
- end
221
-
222
- it "is destroyed if failed more than Job#max_attempts times" do
223
- Delayed::Settings.max_attempts = 25
224
- expect(@job).to receive(:destroy)
225
- @job.max_attempts = 2
226
- @job.save!
227
- 2.times { @job.reschedule }
228
- end
229
-
230
- it "is destroyed if it has expired" do
231
- job = Delayed::Job.create payload_object: SimpleJob.new, expires_at: Delayed::Job.db_time_now - 1.day
232
- expect(job).to receive(:destroy)
233
- job.reschedule
234
- end
235
- end
236
-
237
- context "and we don't want to destroy jobs" do
238
- before do
239
- Delayed::Worker.on_max_failures = proc { false }
240
- end
241
-
242
- after do
243
- Delayed::Worker.on_max_failures = nil
244
- end
245
-
246
- it "is failed if it failed more than Settings.max_attempts times" do
247
- expect(@job.failed_at).to eq(nil)
248
- Delayed::Settings.max_attempts.times { @job.reschedule }
249
- expect(Delayed::Job.list_jobs(:failed, 100).size).to eq(1)
250
- end
251
-
252
- it "is not failed if it failed fewer than Settings.max_attempts times" do
253
- (Delayed::Settings.max_attempts - 1).times { @job.reschedule }
254
- @job = Delayed::Job.find(@job.id)
255
- expect(@job.failed_at).to eq(nil)
256
- end
257
-
258
- it "is failed if it has expired" do
259
- job = Delayed::Job.create payload_object: SimpleJob.new, expires_at: Delayed::Job.db_time_now - 1.day
260
- expect(job).to receive(:fail!)
261
- job.reschedule
262
- end
263
- end
264
-
265
- context "and we give an on_max_failures callback" do
266
- it "is failed max_attempts times and cb is false" do
267
- Delayed::Worker.on_max_failures = proc do |job, _ex|
268
- expect(job).to eq(@job)
269
- false
270
- end
271
- expect(@job).to receive(:fail!)
272
- Delayed::Settings.max_attempts.times { @job.reschedule }
273
- end
274
-
275
- it "is destroyed if it failed max_attempts times and cb is true" do
276
- Delayed::Worker.on_max_failures = proc do |job, _ex|
277
- expect(job).to eq(@job)
278
- true
279
- end
280
- expect(@job).to receive(:destroy)
281
- Delayed::Settings.max_attempts.times { @job.reschedule }
282
- end
283
- end
284
- end
285
-
286
- context "Queue workers" do
287
- before do
288
- Delayed::Settings.queue = "Queue workers test"
289
- job_create(queue: "queue1")
290
- job_create(queue: "queue2")
291
- end
292
-
293
- it "onlies work off jobs assigned to themselves" do
294
- worker = worker_create(queue: "queue1")
295
- expect(SimpleJob.runs).to eq(0)
296
- worker.run
297
- expect(SimpleJob.runs).to eq(1)
298
-
299
- SimpleJob.runs = 0
300
-
301
- worker = worker_create(queue: "queue2")
302
- expect(SimpleJob.runs).to eq(0)
303
- worker.run
304
- expect(SimpleJob.runs).to eq(1)
305
- end
306
-
307
- it "does not work off jobs not assigned to themselves" do
308
- worker = worker_create(queue: "queue3")
309
-
310
- expect(SimpleJob.runs).to eq(0)
311
- worker.run
312
- expect(SimpleJob.runs).to eq(0)
313
- end
314
-
315
- it "gets the default queue if none is set" do
316
- queue_name = "default_queue"
317
- Delayed::Settings.queue = queue_name
318
- worker = worker_create(queue: nil)
319
- expect(worker.queue_name).to eq(queue_name)
320
- end
321
-
322
- it "overrides default queue name if specified in initialize" do
323
- queue_name = "my_queue"
324
- Delayed::Settings.queue = "default_queue"
325
- worker = worker_create(queue: queue_name)
326
- expect(worker.queue_name).to eq(queue_name)
327
- end
328
- end
329
-
330
- context "plugins" do
331
- it "creates and call the plugin callbacks" do
332
- TestPlugin.runs = 0
333
- Delayed::Worker.plugins << TestPlugin
334
- job_create
335
- @worker = Delayed::Worker.new(quiet: true)
336
- @worker.run
337
- expect(TestPlugin.runs).to eq(1)
338
- expect(SimpleJob.runs).to eq(1)
339
- end
340
- end
341
-
342
- describe "expires_at" do
343
- it "runs non-expired jobs" do
344
- Delayed::Job.enqueue SimpleJob.new, expires_at: Delayed::Job.db_time_now + 1.day
345
- expect { @worker.run }.to change(SimpleJob, :runs).by(1)
346
- end
347
-
348
- it "does not run expired jobs" do
349
- Delayed::Job.enqueue SimpleJob.new, expires_at: Delayed::Job.db_time_now - 1.day
350
- expect { @worker.run }.to change(SimpleJob, :runs).by(0)
351
- end
352
-
353
- it "reports a permanent failure when an expired job is dequeued" do
354
- ErrorJob.last_error = nil
355
- Delayed::Job.enqueue ErrorJob.new, expires_at: Delayed::Job.db_time_now - 1.day
356
- expect { @worker.run }.to change(ErrorJob, :permanent_failure_runs).by(1)
357
- expect(ErrorJob.last_error).to be_a Delayed::Backend::JobExpired
358
- end
359
- end
360
-
361
- describe "delay failure callbacks" do
362
- it "calls the on_failure callback" do
363
- ErrorJob.last_error = nil
364
- ErrorJob.new.delay(max_attempts: 2, on_failure: :on_failure).perform
365
- expect { @worker.run }.to change(ErrorJob, :failure_runs).by(1)
366
- expect(ErrorJob.last_error.to_s).to eq "did not work"
367
- end
368
-
369
- it "calls the on_permanent_failure callback" do
370
- ErrorJob.last_error = nil
371
- ErrorJob.new.delay(max_attempts: 1, on_permanent_failure: :on_failure).perform
372
- expect { @worker.run }.to change(ErrorJob, :failure_runs).by(1)
373
- expect(ErrorJob.last_error.to_s).to eq "did not work"
374
- end
375
- end
376
-
377
- describe "custom deserialization errors" do
378
- it "reschedules with more attempts left" do
379
- job = Delayed::Job.create({ payload_object: DeserializeErrorJob.new, max_attempts: 2 })
380
- job.instance_variable_set("@payload_object", nil)
381
- worker = Delayed::Worker.new(max_priority: nil, min_priority: nil, quiet: true)
382
- expect { worker.perform(job) }.not_to raise_error
383
- end
384
-
385
- it "run permanent failure code on last attempt" do
386
- job = Delayed::Job.create({ payload_object: DeserializeErrorJob.new, max_attempts: 1 })
387
- job.instance_variable_set("@payload_object", nil)
388
- worker = Delayed::Worker.new(max_priority: nil, min_priority: nil, quiet: true)
389
- expect { worker.perform(job) }.not_to raise_error
390
- end
391
- end
392
-
393
- describe "#start" do
394
- it "fires off an execute callback on the processing jobs loop" do
395
- fired = false
396
- expect(@worker).to receive(:exit?).and_return(true)
397
- Delayed::Worker.lifecycle.before(:execute) { |w| w == @worker && fired = true }
398
- @worker.start
399
- expect(fired).to eq(true)
400
- end
401
- end
402
-
403
- describe "#run" do
404
- it "fires off a loop callback on each call to run" do
405
- fired = 0
406
- Delayed::Worker.lifecycle.before(:loop) { |w| w == @worker && fired += 1 }
407
- expect(Delayed::Job).to receive(:get_and_lock_next_available).twice.and_return(nil)
408
- @worker.run
409
- @worker.run
410
- expect(fired).to eq(2)
411
- end
412
- end
413
- end
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "shared/delayed_batch"
4
- require_relative "shared/delayed_method"
5
- require_relative "shared/performable_method"
6
- require_relative "shared/shared_backend"
7
- require_relative "shared/testing"
8
- require_relative "shared/worker"
9
-
10
- shared_examples_for "a delayed_jobs implementation" do
11
- include_examples "a backend"
12
- include_examples "Delayed::Batch"
13
- include_examples "random ruby objects"
14
- include_examples "Delayed::PerformableMethod"
15
- include_examples "Delayed::Worker"
16
- include_examples "Delayed::Testing"
17
- end
data/spec/spec_helper.rb DELETED
@@ -1,136 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "delayed_job"
4
- require "delayed/testing"
5
-
6
- require "database_cleaner"
7
- require "fileutils"
8
- require "rack/test"
9
- require "timecop"
10
- require "webmock/rspec"
11
-
12
- require "pry"
13
- require "byebug"
14
-
15
- RSpec.configure do |config|
16
- config.expect_with(:rspec) do |c|
17
- c.syntax = %i[should expect]
18
- end
19
-
20
- config.before(:suite) do
21
- DatabaseCleaner.strategy = :transaction
22
- DatabaseCleaner.clean_with(:truncation)
23
- WebMock.disable_net_connect!
24
- end
25
-
26
- config.before do |example|
27
- DatabaseCleaner.strategy = if example.metadata[:sinatra] || example.metadata[:non_transactional]
28
- :truncation
29
- else
30
- :transaction
31
- end
32
- DatabaseCleaner.start
33
- end
34
-
35
- config.after do
36
- DatabaseCleaner.clean
37
- end
38
- end
39
-
40
- module NoYamlDump
41
- def encode_with(coder); end
42
- end
43
- # example groups are often the sender, and if we try to serialize them,
44
- # the resultant object is then encoded in the sender, and then we serialize
45
- # again, and it just keeps getting bigger and bigger and bigger...
46
- RSpec::Core::ExampleGroup.include(NoYamlDump)
47
-
48
- ENV["TEST_ENV_NUMBER"] ||= "1"
49
- ENV["TEST_DB_HOST"] ||= "localhost"
50
- ENV["TEST_DB_DATABASE"] ||= "inst-jobs-test-#{ENV['TEST_ENV_NUMBER']}"
51
-
52
- connection_config = {
53
- adapter: :postgresql,
54
- host: ENV["TEST_DB_HOST"].presence,
55
- encoding: "utf8",
56
- username: ENV["TEST_DB_USERNAME"],
57
- database: ENV["TEST_DB_DATABASE"],
58
- min_messages: "notice"
59
- }
60
-
61
- def migrate(file)
62
- ActiveRecord::MigrationContext.new(file, ActiveRecord::SchemaMigration).migrate
63
- end
64
-
65
- # create the test db if it does not exist, to help out wwtd
66
- ActiveRecord::Base.establish_connection(connection_config.merge(database: "postgres"))
67
- begin
68
- ActiveRecord::Base.connection.create_database(connection_config[:database])
69
- rescue ActiveRecord::StatementInvalid
70
- nil
71
- end
72
- ActiveRecord::Base.establish_connection(connection_config)
73
-
74
- # we need to ensure this callback is called for activerecord-pg-extensions,
75
- # which isn't running because we're not using Rails to setup the database
76
- ActiveRecord::PGExtensions::Railtie.run_initializers
77
-
78
- # TODO: reset db and migrate again, to test migrations
79
-
80
- migrate("db/migrate")
81
- migrate("spec/migrate")
82
- Delayed::Backend::ActiveRecord::Job.reset_column_information
83
- Delayed::Backend::ActiveRecord::Job::Failed.reset_column_information
84
-
85
- Time.zone = "UTC" # rubocop:disable Rails/TimeZoneAssignment
86
- FileUtils.mkdir_p("tmp")
87
- ActiveRecord::Base.logger = Rails.logger = Logger.new("tmp/test.log")
88
-
89
- # Purely useful for test cases...
90
- class Story < ActiveRecord::Base
91
- def tell
92
- text
93
- end
94
-
95
- def whatever(times, _)
96
- tell * times
97
- end
98
-
99
- def whatever_else(times, _)
100
- tell * times
101
- end
102
-
103
- handle_asynchronously :whatever
104
- handle_asynchronously :whatever_else, queue: "testqueue"
105
- end
106
-
107
- class StoryReader
108
- def read(story)
109
- "Epilog: #{story.tell}"
110
- end
111
-
112
- def self.reverse(str)
113
- str.reverse
114
- end
115
- end
116
-
117
- module MyReverser
118
- def self.reverse(str)
119
- str.reverse
120
- end
121
- end
122
-
123
- def change_setting(klass, setting_name, value)
124
- old_val = klass.send(setting_name)
125
- klass.send("#{setting_name}=", value)
126
- yield
127
- ensure
128
- klass.send("#{setting_name}=", old_val)
129
- end
130
-
131
- def run_job(job)
132
- Delayed::Testing.run_job(job)
133
- end
134
-
135
- require_relative "sample_jobs"
136
- require_relative "shared_jobs_specs"