inst-jobs 2.3.3 → 2.4.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/db/migrate/20101216224513_create_delayed_jobs.rb +9 -7
  3. data/db/migrate/20110531144916_cleanup_delayed_jobs_indexes.rb +8 -13
  4. data/db/migrate/20110610213249_optimize_delayed_jobs.rb +8 -8
  5. data/db/migrate/20110831210257_add_delayed_jobs_next_in_strand.rb +25 -25
  6. data/db/migrate/20120510004759_delayed_jobs_delete_trigger_lock_for_update.rb +4 -8
  7. data/db/migrate/20120531150712_drop_psql_jobs_pop_fn.rb +1 -3
  8. data/db/migrate/20120607164022_delayed_jobs_use_advisory_locks.rb +11 -15
  9. data/db/migrate/20120607181141_index_jobs_on_locked_by.rb +1 -1
  10. data/db/migrate/20120608191051_add_jobs_run_at_index.rb +2 -2
  11. data/db/migrate/20120927184213_change_delayed_jobs_handler_to_text.rb +1 -1
  12. data/db/migrate/20140505215510_copy_failed_jobs_original_id.rb +2 -3
  13. data/db/migrate/20150807133223_add_max_concurrent_to_jobs.rb +9 -13
  14. data/db/migrate/20151210162949_improve_max_concurrent.rb +4 -8
  15. data/db/migrate/20161206323555_add_back_default_string_limits_jobs.rb +3 -2
  16. data/db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb +13 -17
  17. data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +8 -8
  18. data/db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb +72 -77
  19. data/db/migrate/20200825011002_add_strand_order_override.rb +93 -97
  20. data/db/migrate/20210809145804_add_n_strand_index.rb +3 -3
  21. data/db/migrate/20210812210128_add_singleton_column.rb +200 -0
  22. data/db/migrate/20210917232626_add_delete_conflicting_singletons_before_unlock_trigger.rb +27 -0
  23. data/db/migrate/20210928174754_fix_singleton_condition_in_before_insert.rb +56 -0
  24. data/exe/inst_jobs +3 -2
  25. data/lib/delayed/backend/active_record.rb +204 -150
  26. data/lib/delayed/backend/base.rb +106 -82
  27. data/lib/delayed/batch.rb +11 -9
  28. data/lib/delayed/cli.rb +98 -84
  29. data/lib/delayed/core_ext/kernel.rb +4 -2
  30. data/lib/delayed/daemon.rb +70 -74
  31. data/lib/delayed/job_tracking.rb +26 -25
  32. data/lib/delayed/lifecycle.rb +27 -24
  33. data/lib/delayed/log_tailer.rb +17 -17
  34. data/lib/delayed/logging.rb +13 -16
  35. data/lib/delayed/message_sending.rb +43 -52
  36. data/lib/delayed/performable_method.rb +6 -8
  37. data/lib/delayed/periodic.rb +72 -65
  38. data/lib/delayed/plugin.rb +2 -4
  39. data/lib/delayed/pool.rb +198 -193
  40. data/lib/delayed/server/helpers.rb +6 -6
  41. data/lib/delayed/server.rb +51 -54
  42. data/lib/delayed/settings.rb +93 -81
  43. data/lib/delayed/testing.rb +21 -22
  44. data/lib/delayed/version.rb +1 -1
  45. data/lib/delayed/work_queue/in_process.rb +21 -18
  46. data/lib/delayed/work_queue/parent_process/client.rb +54 -55
  47. data/lib/delayed/work_queue/parent_process/server.rb +219 -208
  48. data/lib/delayed/work_queue/parent_process.rb +52 -53
  49. data/lib/delayed/worker/consul_health_check.rb +21 -19
  50. data/lib/delayed/worker/health_check.rb +29 -22
  51. data/lib/delayed/worker/null_health_check.rb +3 -1
  52. data/lib/delayed/worker/process_helper.rb +8 -9
  53. data/lib/delayed/worker.rb +271 -265
  54. data/lib/delayed/yaml_extensions.rb +12 -10
  55. data/lib/delayed_job.rb +37 -38
  56. data/lib/inst-jobs.rb +1 -1
  57. data/spec/active_record_job_spec.rb +129 -136
  58. data/spec/delayed/cli_spec.rb +7 -7
  59. data/spec/delayed/daemon_spec.rb +10 -9
  60. data/spec/delayed/message_sending_spec.rb +16 -9
  61. data/spec/delayed/periodic_spec.rb +13 -12
  62. data/spec/delayed/server_spec.rb +38 -38
  63. data/spec/delayed/settings_spec.rb +26 -25
  64. data/spec/delayed/work_queue/in_process_spec.rb +7 -8
  65. data/spec/delayed/work_queue/parent_process/client_spec.rb +17 -12
  66. data/spec/delayed/work_queue/parent_process/server_spec.rb +70 -41
  67. data/spec/delayed/work_queue/parent_process_spec.rb +21 -23
  68. data/spec/delayed/worker/consul_health_check_spec.rb +22 -22
  69. data/spec/delayed/worker/health_check_spec.rb +60 -52
  70. data/spec/delayed/worker_spec.rb +28 -25
  71. data/spec/sample_jobs.rb +45 -15
  72. data/spec/shared/delayed_batch.rb +74 -67
  73. data/spec/shared/delayed_method.rb +143 -102
  74. data/spec/shared/performable_method.rb +39 -38
  75. data/spec/shared/shared_backend.rb +547 -441
  76. data/spec/shared/testing.rb +14 -14
  77. data/spec/shared/worker.rb +155 -147
  78. data/spec/shared_jobs_specs.rb +13 -13
  79. data/spec/spec_helper.rb +46 -41
  80. metadata +79 -55
  81. data/lib/delayed/backend/redis/bulk_update.lua +0 -50
  82. data/lib/delayed/backend/redis/destroy_job.lua +0 -2
  83. data/lib/delayed/backend/redis/enqueue.lua +0 -29
  84. data/lib/delayed/backend/redis/fail_job.lua +0 -5
  85. data/lib/delayed/backend/redis/find_available.lua +0 -3
  86. data/lib/delayed/backend/redis/functions.rb +0 -59
  87. data/lib/delayed/backend/redis/get_and_lock_next_available.lua +0 -17
  88. data/lib/delayed/backend/redis/includes/jobs_common.lua +0 -203
  89. data/lib/delayed/backend/redis/job.rb +0 -528
  90. data/lib/delayed/backend/redis/set_running.lua +0 -5
  91. data/lib/delayed/backend/redis/tickle_strand.lua +0 -2
  92. data/spec/gemfiles/52.gemfile +0 -7
  93. data/spec/gemfiles/60.gemfile +0 -7
  94. data/spec/gemfiles/60.gemfile.lock +0 -246
  95. data/spec/gemfiles/61.gemfile +0 -7
  96. data/spec/redis_job_spec.rb +0 -148
@@ -1,98 +1,105 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- shared_examples_for 'Delayed::Batch' do
3
+ shared_examples_for "Delayed::Batch" do
4
4
  context "batching" do
5
- it "should batch up all deferrable delayed methods" do
5
+ it "batches up all deferrable delayed methods" do
6
6
  later = 1.hour.from_now
7
- Delayed::Batch.serial_batch {
8
- "string".delay(ignore_transaction: true).size.should be true
9
- "string".delay(run_at: later, ignore_transaction: true).reverse.should be_truthy # won't be batched, it'll get its own job
10
- "string".delay(ignore_transaction: true).gsub(/./, "!").should be_truthy
11
- }
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
12
13
  batch_jobs = Delayed::Job.find_available(5)
13
14
  regular_jobs = Delayed::Job.list_jobs(:future, 5)
14
- regular_jobs.size.should == 1
15
- regular_jobs.first.batch?.should == false
16
- batch_jobs.size.should == 1
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)
17
18
  batch_job = batch_jobs.first
18
- batch_job.batch?.should == true
19
- batch_job.payload_object.mode.should == :serial
20
- batch_job.payload_object.jobs.map { |j| [j.payload_object.object, j.payload_object.method, j.payload_object.args] }.should == [
21
- ["string", :size, []],
22
- ["string", :gsub, [/./, "!"]]
23
- ]
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
+ ])
24
33
  end
25
34
 
26
- it "should not let you invoke it directly" do
27
- later = 1.hour.from_now
28
- Delayed::Batch.serial_batch {
29
- "string".delay(ignore_transaction: true).size.should be true
30
- "string".delay(ignore_transaction: true).gsub(/./, "!").should be true
31
- }
32
- Delayed::Job.jobs_count(:current).should == 1
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)
33
41
  job = Delayed::Job.find_available(1).first
34
- expect{ job.invoke_job }.to raise_error(RuntimeError)
42
+ expect { job.invoke_job }.to raise_error(RuntimeError)
35
43
  end
36
44
 
37
- it "should create valid jobs" do
38
- Delayed::Batch.serial_batch {
39
- "string".delay(ignore_transaction: true).size.should be true
40
- "string".delay(ignore_transaction: true).gsub(/./, "!").should be true
41
- }
42
- Delayed::Job.jobs_count(:current).should == 1
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)
43
51
 
44
52
  batch_job = Delayed::Job.find_available(1).first
45
- batch_job.batch?.should == true
53
+ expect(batch_job.batch?).to eq(true)
46
54
  jobs = batch_job.payload_object.jobs
47
- jobs.size.should == 2
48
- jobs[0].should be_new_record
49
- jobs[0].payload_object.class.should == Delayed::PerformableMethod
50
- jobs[0].payload_object.method.should == :size
51
- jobs[0].payload_object.args.should == []
52
- jobs[0].payload_object.perform.should == 6
53
- jobs[1].should be_new_record
54
- jobs[1].payload_object.class.should == Delayed::PerformableMethod
55
- jobs[1].payload_object.method.should == :gsub
56
- jobs[1].payload_object.args.should == [/./, "!"]
57
- jobs[1].payload_object.perform.should == "!!!!!!"
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("!!!!!!")
58
66
  end
59
67
 
60
- it "should create a different batch for each priority" do
61
- later = 1.hour.from_now
62
- Delayed::Batch.serial_batch {
63
- "string".delay(priority: Delayed::LOW_PRIORITY, ignore_transaction: true).size.should be true
64
- "string".delay(ignore_transaction: true).gsub(/./, "!").should be true
65
- }
66
- Delayed::Job.jobs_count(:current).should == 2
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)
67
74
  end
68
75
 
69
- it "should use the given priority for all, if specified" do
70
- Delayed::Batch.serial_batch(:priority => 11) {
71
- "string".delay(priority: 20, ignore_transaction: true).size.should be true
72
- "string".delay(priority: 15, ignore_transaction: true).gsub(/./, "!").should be true
73
- }
74
- Delayed::Job.jobs_count(:current).should == 1
75
- Delayed::Job.find_available(1).first.priority.should == 11
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)
76
83
  end
77
84
 
78
- it "should just create the job, if there's only one in the batch" do
79
- Delayed::Batch.serial_batch(:priority => 11) {
80
- "string".delay(ignore_transaction: true).size.should be true
81
- }
82
- Delayed::Job.jobs_count(:current).should == 1
83
- Delayed::Job.find_available(1).first.tag.should == "String#size"
84
- Delayed::Job.find_available(1).first.priority.should == 11
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)
85
92
  end
86
93
 
87
- it "should list a job only once when the same call is made multiple times" do
88
- Delayed::Batch.serial_batch(:priority => 11) {
94
+ it "lists a job only once when the same call is made multiple times" do
95
+ Delayed::Batch.serial_batch(priority: 11) do
89
96
  "string".delay(ignore_transaction: true).size
90
97
  "string".delay(ignore_transaction: true).gsub(/./, "!")
91
98
  "string".delay(ignore_transaction: true).size
92
- }
99
+ end
93
100
  batch_job = Delayed::Job.find_available(1).first
94
101
  jobs = batch_job.payload_object.jobs
95
- jobs.size.should == 2
102
+ expect(jobs.size).to eq(2)
96
103
  end
97
104
  end
98
105
  end
@@ -1,131 +1,183 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- shared_examples_for 'random ruby objects' do
4
- def set_queue(name)
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
5
19
  old_name = Delayed::Settings.queue
6
20
  Delayed::Settings.queue = name
7
21
  ensure
8
22
  Delayed::Settings.queue = old_name
9
23
  end
10
24
 
11
- it "should respond_to :delay method" do
25
+ it "respond_toes :delay method" do
12
26
  Object.new.respond_to?(:delay)
13
27
  end
14
28
 
15
- it "should raise a ArgumentError if delay is called but the target method doesn't exist" do
16
- lambda { Object.new.delay.method_that_deos_not_exist }.should raise_error(NoMethodError)
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)
17
31
  end
18
32
 
19
- it "should add a new entry to the job table when delay is called on it" do
20
- lambda { Object.new.delay.to_s }.should change { Delayed::Job.jobs_count(:current) }.by(1)
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)
21
35
  end
22
36
 
23
- it "should add a new entry to the job table when delay is called on it with a queue" do
24
- lambda { Object.new.delay(queue: "testqueue").to_s }.should change { Delayed::Job.jobs_count(:current, "testqueue") }.by(1)
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)
25
41
  end
26
42
 
27
- it "should add a new entry to the job table when delay is called on the class" do
28
- lambda { Object.delay.to_s }.should change { Delayed::Job.jobs_count(:current) }.by(1)
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)
29
45
  end
30
46
 
31
- it "should add a new entry to the job table when delay is called on the class with a queue" do
32
- lambda { Object.delay(queue: "testqueue").to_s }.should change { Delayed::Job.jobs_count(:current, "testqueue") }.by(1)
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)
33
49
  end
34
50
 
35
51
  context "class methods" do
36
52
  context "handle_asynchronously" do
37
- it "should work with default_async" do
53
+ it "works with default_async" do
38
54
  klass = Class.new do
39
55
  attr_reader :ran
40
- def test_method; @ran = true; end
56
+
57
+ def test_method
58
+ @ran = true
59
+ end
41
60
  handle_asynchronously :test_method
42
61
  end
43
62
  obj = klass.new
44
- lambda { obj.test_method }.should change { Delayed::Job.jobs_count(:current) }.by(1)
45
- obj.ran.should be_falsey
46
- lambda { obj.test_method(synchronous: true) }.should_not change { Delayed::Job.jobs_count(:current) }
47
- obj.ran.should be true
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
48
67
  end
49
68
 
50
- it 'must work with enqueue args that are lambdas' do
69
+ it "must work with enqueue args that are lambdas" do
51
70
  klass = Class.new do
52
71
  attr_reader :ran
53
- def test_method; @ran = true; end
54
- handle_asynchronously :test_method, singleton: -> (obj) { "foobar:#{obj.object_id}" }
72
+
73
+ def test_method
74
+ @ran = true
75
+ end
76
+ handle_asynchronously :test_method, singleton: ->(obj) { "foobar:#{obj.object_id}" }
55
77
  end
56
78
 
57
79
  obj = klass.new
58
- lambda { obj.test_method }.should change { Delayed::Job.jobs_count(:current) }.by(1)
80
+ expect { obj.test_method }.to change { Delayed::Job.jobs_count(:current) }.by(1)
59
81
  end
60
82
 
61
- it 'must work with kwargs in the original method' do
83
+ it "must work with kwargs in the original method" do
62
84
  klass = Class.new do
63
85
  attr_reader :run
64
- def test_method(my_kwarg: nil); @run = my_kwarg; end
86
+
87
+ def test_method(my_kwarg: nil)
88
+ @run = my_kwarg
89
+ end
65
90
  handle_asynchronously :test_method
66
91
 
67
- def other_test(arg); @foo = arg; end
92
+ def other_test(arg)
93
+ @foo = arg
94
+ end
68
95
  handle_asynchronously :other_test
69
96
  end
70
97
 
71
98
  obj = klass.new
72
- obj.test_method(my_kwarg: 'foo', synchronous: true)
73
- expect(obj.run).to eq 'foo'
99
+ obj.test_method(my_kwarg: "foo", synchronous: true)
100
+ expect(obj.run).to eq "foo"
74
101
  end
75
102
 
76
- it "should send along enqueue args and args" do
103
+ it "sends along enqueue args and args" do
77
104
  klass = Class.new do
78
105
  attr_accessor :ran
79
- def test_method(*args); @ran = args; end
80
- handle_asynchronously(:test_method, enqueue_arg_1: :thing)
106
+
107
+ def test_method(*args)
108
+ @ran = args
109
+ end
110
+ handle_asynchronously(:test_method, enqueue_arg1: :thing)
81
111
  end
82
112
  obj = klass.new
83
- method = double()
84
-
85
- expect(Delayed::PerformableMethod).to receive(:new).with(obj, :test_method, args: [1,2,3], kwargs: {synchronous: true}, on_failure: nil, on_permanent_failure: nil, sender: obj).and_return(method)
86
- expect(Delayed::Job).to receive(:enqueue).with(method, :enqueue_arg_1 => :thing)
87
- obj.test_method(1,2,3)
88
-
89
- expect(Delayed::PerformableMethod).to receive(:new).with(obj, :test_method, args: [4], kwargs: {:synchronous=>true}, on_failure: nil, on_permanent_failure: nil, sender: obj).and_return(method)
90
- expect(Delayed::Job).to receive(:enqueue).with(method, :enqueue_arg_1 => :thing)
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)
91
137
  obj.test_method(4)
92
138
 
93
- obj.ran.should be_nil
139
+ expect(obj.ran).to be_nil
94
140
  obj.test_method(7, synchronous: true)
95
- obj.ran.should == [7]
141
+ expect(obj.ran).to eq([7])
96
142
  obj.ran = nil
97
- obj.ran.should == nil
98
- obj.test_method(8,9, synchronous: true)
99
- obj.ran.should == [8,9]
143
+ expect(obj.ran).to eq(nil)
144
+ obj.test_method(8, 9, synchronous: true)
145
+ expect(obj.ran).to eq([8, 9])
100
146
  end
101
147
 
102
- it "should handle punctuation correctly" do
148
+ it "handles punctuation correctly" do
103
149
  klass = Class.new do
104
150
  attr_reader :ran
105
- def test_method?; @ran = true; end
151
+
152
+ def test_method?
153
+ @ran = true
154
+ end
106
155
  handle_asynchronously :test_method?
107
156
  end
108
157
  obj = klass.new
109
- lambda { obj.test_method? }.should change { Delayed::Job.jobs_count(:current) }.by(1)
110
- obj.ran.should be_falsey
111
- lambda { obj.test_method?(synchronous: true) }.should_not change { Delayed::Job.jobs_count(:current) }
112
- obj.ran.should be true
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
113
162
  end
114
163
 
115
- it "should handle assignment punctuation correctly" do
164
+ it "handles assignment punctuation correctly" do
116
165
  klass = Class.new do
117
166
  attr_reader :ran
118
- def test_method=(val); @ran = val; end
167
+
168
+ def test_method=(val)
169
+ @ran = val
170
+ end
119
171
  handle_asynchronously :test_method=
120
172
  end
121
173
  obj = klass.new
122
- lambda { obj.test_method = 3 }.should change { Delayed::Job.jobs_count(:current) }.by(1)
123
- obj.ran.should be_nil
124
- lambda { obj.send(:test_method=, 5, synchronous: true) }.should_not change { Delayed::Job.jobs_count(:current) }
125
- obj.ran.should == 5
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)
126
178
  end
127
179
 
128
- it "should correctly sort out method accessibility" do
180
+ it "correctlies sort out method accessibility" do
129
181
  klass1 = Class.new do
130
182
  def test_method; end
131
183
  handle_asynchronously :test_method
@@ -133,114 +185,103 @@ shared_examples_for 'random ruby objects' do
133
185
 
134
186
  klass2 = Class.new do
135
187
  protected
188
+
136
189
  def test_method; end
137
190
  handle_asynchronously :test_method
138
191
  end
139
192
 
140
193
  klass3 = Class.new do
141
194
  private
195
+
142
196
  def test_method; end
143
197
  handle_asynchronously :test_method
144
198
  end
145
199
 
146
- klass1.public_method_defined?(:test_method).should be true
147
- klass2.protected_method_defined?(:test_method).should be true
148
- klass3.private_method_defined?(:test_method).should be true
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
149
203
  end
150
204
  end
151
205
  end
152
206
 
153
- it "should call send later on methods which are wrapped with handle_asynchronously" do
154
- story = Story.create :text => 'Once upon...'
207
+ it "calls send later on methods which are wrapped with handle_asynchronously" do
208
+ story = Story.create text: "Once upon..."
155
209
 
156
210
  expect { story.whatever(1, 5) }.to change { Delayed::Job.jobs_count(:current) }.by(1)
157
211
 
158
212
  job = Delayed::Job.list_jobs(:current, 1).first
159
- job.payload_object.class.should == Delayed::PerformableMethod
160
- job.payload_object.method.should == :whatever
161
- job.payload_object.args.should == [1, 5]
162
- job.payload_object.kwargs.should == {:synchronous=>true}
163
- job.payload_object.perform.should == 'Once upon...'
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...")
164
218
  end
165
219
 
166
220
  context "delay" do
167
- it "should use the default queue if there is one" do
221
+ it "uses the default queue if there is one" do
168
222
  set_queue("testqueue") do
169
223
  "string".delay.reverse
170
224
  job = Delayed::Job.list_jobs(:current, 1).first
171
- job.queue.should == "testqueue"
225
+ expect(job.queue).to eq("testqueue")
172
226
 
173
227
  "string".delay(queue: nil).reverse
174
228
  job2 = Delayed::Job.list_jobs(:current, 2).last
175
- job2.queue.should == "testqueue"
229
+ expect(job2.queue).to eq("testqueue")
176
230
  end
177
231
  end
178
232
 
179
- it "should require a queue" do
233
+ it "requires a queue" do
180
234
  expect { set_queue(nil) }.to raise_error(ArgumentError)
181
235
  end
182
236
  end
183
237
 
184
238
  context "delay with run_at" do
185
- it "should queue a new job" do
186
- lambda do
239
+ it "queues a new job" do
240
+ expect do
187
241
  "string".delay(run_at: 1.hour.from_now).length
188
- end.should change { Delayed::Job.jobs_count(:future) }.by(1)
242
+ end.to change { Delayed::Job.jobs_count(:future) }.by(1)
189
243
  end
190
244
 
191
- it "should schedule the job in the future" do
245
+ it "schedules the job in the future" do
192
246
  time = 1.hour.from_now
193
247
  "string".delay(run_at: time).length
194
248
  job = Delayed::Job.list_jobs(:future, 1).first
195
- job.run_at.to_i.should == time.to_i
249
+ expect(job.run_at.to_i).to eq(time.to_i)
196
250
  end
197
251
 
198
- it "should store payload as PerformableMethod" do
199
- "string".delay(run_at: 1.hour.from_now).count('r')
252
+ it "stores payload as PerformableMethod" do
253
+ "string".delay(run_at: 1.hour.from_now).count("r")
200
254
  job = Delayed::Job.list_jobs(:future, 1).first
201
- job.payload_object.class.should == Delayed::PerformableMethod
202
- job.payload_object.method.should == :count
203
- job.payload_object.args.should == ['r']
204
- job.payload_object.perform.should == 1
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)
205
259
  end
206
260
 
207
- it "should use the default queue if there is one" do
261
+ it "uses the default queue if there is one" do
208
262
  set_queue("testqueue") do
209
263
  "string".delay(run_at: 1.hour.from_now).reverse
210
264
  job = Delayed::Job.list_jobs(:current, 1).first
211
- job.queue.should == "testqueue"
265
+ expect(job.queue).to eq("testqueue")
212
266
  end
213
267
  end
214
268
  end
215
269
 
216
270
  describe "delay with synchronous argument" do
217
- module UnlessInJob
218
- @runs = 0
219
- def self.runs; @runs; end
220
-
221
- def self.run
222
- @runs += 1
223
- end
224
-
225
- def self.run_later
226
- self.delay(synchronous: Delayed::Job.in_delayed_job?).run
227
- end
228
- end
229
-
230
271
  before do
231
- UnlessInJob.class_eval { @runs = 0 }
272
+ UnlessInJob.runs = 0
232
273
  end
233
274
 
234
- it "should perform immediately if in job" do
275
+ it "performs immediately if in job" do
235
276
  UnlessInJob.delay.run_later
236
277
  job = Delayed::Job.list_jobs(:current, 1).first
237
278
  job.invoke_job
238
- UnlessInJob.runs.should == 1
279
+ expect(UnlessInJob.runs).to eq(1)
239
280
  end
240
281
 
241
- it "should queue up for later if not in job" do
282
+ it "queues up for later if not in job" do
242
283
  UnlessInJob.run_later
243
- UnlessInJob.runs.should == 0
284
+ expect(UnlessInJob.runs).to eq(0)
244
285
  end
245
286
  end
246
287
  end