inst-jobs 0.15.22 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/db/migrate/20101216224513_create_delayed_jobs.rb +2 -0
  3. data/db/migrate/20110208031356_add_delayed_jobs_tag.rb +2 -0
  4. data/db/migrate/20110426161613_add_delayed_jobs_max_attempts.rb +2 -0
  5. data/db/migrate/20110516225834_add_delayed_jobs_strand.rb +2 -0
  6. data/db/migrate/20110531144916_cleanup_delayed_jobs_indexes.rb +2 -0
  7. data/db/migrate/20110610213249_optimize_delayed_jobs.rb +2 -0
  8. data/db/migrate/20110831210257_add_delayed_jobs_next_in_strand.rb +2 -0
  9. data/db/migrate/20120510004759_delayed_jobs_delete_trigger_lock_for_update.rb +2 -0
  10. data/db/migrate/20120531150712_drop_psql_jobs_pop_fn.rb +2 -0
  11. data/db/migrate/20120607164022_delayed_jobs_use_advisory_locks.rb +2 -0
  12. data/db/migrate/20120607181141_index_jobs_on_locked_by.rb +2 -0
  13. data/db/migrate/20120608191051_add_jobs_run_at_index.rb +2 -0
  14. data/db/migrate/20120927184213_change_delayed_jobs_handler_to_text.rb +2 -0
  15. data/db/migrate/20140505215131_add_failed_jobs_original_job_id.rb +2 -0
  16. data/db/migrate/20140505215510_copy_failed_jobs_original_id.rb +2 -0
  17. data/db/migrate/20140505223637_drop_failed_jobs_original_id.rb +2 -0
  18. data/db/migrate/20140512213941_add_source_to_jobs.rb +2 -0
  19. data/db/migrate/20150807133223_add_max_concurrent_to_jobs.rb +2 -0
  20. data/db/migrate/20151123210429_add_expires_at_to_jobs.rb +2 -0
  21. data/db/migrate/20151210162949_improve_max_concurrent.rb +2 -0
  22. data/db/migrate/20161206323555_add_back_default_string_limits_jobs.rb +2 -0
  23. data/db/migrate/20181217155351_speed_up_max_concurrent_triggers.rb +2 -0
  24. data/db/migrate/20190726154743_make_critical_columns_not_null.rb +2 -0
  25. data/db/migrate/20200330230722_add_id_to_get_delayed_jobs_index.rb +2 -0
  26. data/db/migrate/20200824222232_speed_up_max_concurrent_delete_trigger.rb +97 -0
  27. data/db/migrate/20200825011002_add_strand_order_override.rb +128 -0
  28. data/lib/delayed/backend/active_record.rb +9 -5
  29. data/lib/delayed/backend/base.rb +34 -20
  30. data/lib/delayed/backend/redis/functions.rb +2 -0
  31. data/lib/delayed/backend/redis/job.rb +2 -0
  32. data/lib/delayed/batch.rb +5 -3
  33. data/lib/delayed/cli.rb +2 -0
  34. data/lib/delayed/core_ext/kernel.rb +9 -0
  35. data/lib/delayed/daemon.rb +2 -0
  36. data/lib/delayed/engine.rb +2 -0
  37. data/lib/delayed/job_tracking.rb +2 -0
  38. data/lib/delayed/lifecycle.rb +2 -0
  39. data/lib/delayed/log_tailer.rb +2 -0
  40. data/lib/delayed/logging.rb +2 -0
  41. data/lib/delayed/message_sending.rb +90 -106
  42. data/lib/delayed/performable_method.rb +34 -6
  43. data/lib/delayed/periodic.rb +6 -4
  44. data/lib/delayed/plugin.rb +2 -0
  45. data/lib/delayed/pool.rb +2 -0
  46. data/lib/delayed/server.rb +2 -0
  47. data/lib/delayed/server/helpers.rb +2 -0
  48. data/lib/delayed/settings.rb +2 -0
  49. data/lib/delayed/testing.rb +2 -0
  50. data/lib/delayed/version.rb +3 -1
  51. data/lib/delayed/work_queue/in_process.rb +2 -0
  52. data/lib/delayed/work_queue/parent_process.rb +2 -0
  53. data/lib/delayed/work_queue/parent_process/client.rb +2 -0
  54. data/lib/delayed/work_queue/parent_process/server.rb +2 -0
  55. data/lib/delayed/worker.rb +2 -0
  56. data/lib/delayed/worker/consul_health_check.rb +3 -1
  57. data/lib/delayed/worker/health_check.rb +2 -0
  58. data/lib/delayed/worker/null_health_check.rb +2 -0
  59. data/lib/delayed/worker/process_helper.rb +2 -0
  60. data/lib/delayed/yaml_extensions.rb +2 -0
  61. data/lib/delayed_job.rb +4 -0
  62. data/lib/inst-jobs.rb +2 -0
  63. data/spec/active_record_job_spec.rb +4 -6
  64. data/spec/delayed/cli_spec.rb +2 -0
  65. data/spec/delayed/daemon_spec.rb +2 -0
  66. data/spec/delayed/message_sending_spec.rb +101 -0
  67. data/spec/delayed/server_spec.rb +2 -4
  68. data/spec/delayed/settings_spec.rb +2 -0
  69. data/spec/delayed/work_queue/in_process_spec.rb +2 -4
  70. data/spec/delayed/work_queue/parent_process/client_spec.rb +2 -4
  71. data/spec/delayed/work_queue/parent_process/server_spec.rb +2 -1
  72. data/spec/delayed/work_queue/parent_process_spec.rb +2 -1
  73. data/spec/delayed/worker/consul_health_check_spec.rb +3 -1
  74. data/spec/delayed/worker/health_check_spec.rb +2 -0
  75. data/spec/delayed/worker_spec.rb +2 -0
  76. data/spec/gemfiles/42.gemfile.lock +192 -0
  77. data/spec/gemfiles/50.gemfile.lock +197 -0
  78. data/spec/gemfiles/51.gemfile.lock +198 -0
  79. data/spec/gemfiles/52.gemfile.lock +206 -0
  80. data/spec/gemfiles/60.gemfile.lock +224 -0
  81. data/spec/migrate/20140924140513_add_story_table.rb +2 -0
  82. data/spec/redis_job_spec.rb +10 -12
  83. data/spec/sample_jobs.rb +2 -0
  84. data/spec/shared/delayed_batch.rb +17 -15
  85. data/spec/shared/delayed_method.rb +49 -204
  86. data/spec/shared/performable_method.rb +11 -9
  87. data/spec/shared/shared_backend.rb +27 -25
  88. data/spec/shared/testing.rb +7 -5
  89. data/spec/shared/worker.rb +15 -13
  90. data/spec/shared_jobs_specs.rb +2 -0
  91. data/spec/spec_helper.rb +12 -1
  92. metadata +36 -7
@@ -0,0 +1,224 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ inst-jobs (1.0.1)
5
+ activerecord (>= 4.2)
6
+ activesupport (>= 4.2)
7
+ after_transaction_commit (>= 1.0, < 3)
8
+ debug_inspector (~> 0.0.3)
9
+ fugit (~> 1.3)
10
+ railties (>= 4.2)
11
+ redis (> 3.0)
12
+ redis-scripting (~> 1.0.1)
13
+
14
+ GEM
15
+ remote: https://rubygems.org/
16
+ specs:
17
+ actioncable (6.0.2)
18
+ actionpack (= 6.0.2)
19
+ nio4r (~> 2.0)
20
+ websocket-driver (>= 0.6.1)
21
+ actionmailbox (6.0.2)
22
+ actionpack (= 6.0.2)
23
+ activejob (= 6.0.2)
24
+ activerecord (= 6.0.2)
25
+ activestorage (= 6.0.2)
26
+ activesupport (= 6.0.2)
27
+ mail (>= 2.7.1)
28
+ actionmailer (6.0.2)
29
+ actionpack (= 6.0.2)
30
+ actionview (= 6.0.2)
31
+ activejob (= 6.0.2)
32
+ mail (~> 2.5, >= 2.5.4)
33
+ rails-dom-testing (~> 2.0)
34
+ actionpack (6.0.2)
35
+ actionview (= 6.0.2)
36
+ activesupport (= 6.0.2)
37
+ rack (~> 2.0)
38
+ rack-test (>= 0.6.3)
39
+ rails-dom-testing (~> 2.0)
40
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
41
+ actiontext (6.0.2)
42
+ actionpack (= 6.0.2)
43
+ activerecord (= 6.0.2)
44
+ activestorage (= 6.0.2)
45
+ activesupport (= 6.0.2)
46
+ nokogiri (>= 1.8.5)
47
+ actionview (6.0.2)
48
+ activesupport (= 6.0.2)
49
+ builder (~> 3.1)
50
+ erubi (~> 1.4)
51
+ rails-dom-testing (~> 2.0)
52
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
53
+ activejob (6.0.2)
54
+ activesupport (= 6.0.2)
55
+ globalid (>= 0.3.6)
56
+ activemodel (6.0.2)
57
+ activesupport (= 6.0.2)
58
+ activerecord (6.0.2)
59
+ activemodel (= 6.0.2)
60
+ activesupport (= 6.0.2)
61
+ activestorage (6.0.2)
62
+ actionpack (= 6.0.2)
63
+ activejob (= 6.0.2)
64
+ activerecord (= 6.0.2)
65
+ marcel (~> 0.3.1)
66
+ activesupport (6.0.2)
67
+ concurrent-ruby (~> 1.0, >= 1.0.2)
68
+ i18n (>= 0.7, < 2)
69
+ minitest (~> 5.1)
70
+ tzinfo (~> 1.1)
71
+ zeitwerk (~> 2.2)
72
+ addressable (2.7.0)
73
+ public_suffix (>= 2.0.2, < 5.0)
74
+ after_transaction_commit (2.2.1)
75
+ activerecord (>= 5.2)
76
+ backports (3.15.0)
77
+ builder (3.2.4)
78
+ bump (0.8.0)
79
+ byebug (11.0.1)
80
+ coderay (1.1.2)
81
+ concurrent-ruby (1.1.7)
82
+ crass (1.0.6)
83
+ database_cleaner (1.6.1)
84
+ debug_inspector (0.0.3)
85
+ diff-lcs (1.3)
86
+ erubi (1.9.0)
87
+ et-orbi (1.2.4)
88
+ tzinfo
89
+ fugit (1.4.0)
90
+ et-orbi (~> 1.1, >= 1.1.8)
91
+ raabro (~> 1.4)
92
+ globalid (0.4.2)
93
+ activesupport (>= 4.2.0)
94
+ httpclient (2.8.3)
95
+ i18n (1.8.5)
96
+ concurrent-ruby (~> 1.0)
97
+ imperium (0.5.2)
98
+ addressable (~> 2.5)
99
+ httpclient (~> 2.8)
100
+ loofah (2.7.0)
101
+ crass (~> 1.0.2)
102
+ nokogiri (>= 1.5.9)
103
+ mail (2.7.1)
104
+ mini_mime (>= 0.1.1)
105
+ marcel (0.3.3)
106
+ mimemagic (~> 0.3.2)
107
+ method_source (0.9.2)
108
+ mimemagic (0.3.5)
109
+ mini_mime (1.0.2)
110
+ mini_portile2 (2.4.0)
111
+ minitest (5.14.2)
112
+ multi_json (1.13.1)
113
+ mustermann (1.0.0.beta2)
114
+ nio4r (2.5.4)
115
+ nokogiri (1.10.10)
116
+ mini_portile2 (~> 2.4.0)
117
+ pg (0.21.0)
118
+ pry (0.12.2)
119
+ coderay (~> 1.1.0)
120
+ method_source (~> 0.9.0)
121
+ public_suffix (4.0.6)
122
+ raabro (1.4.0)
123
+ rack (2.0.7)
124
+ rack-protection (2.0.0.beta2)
125
+ rack
126
+ rack-test (1.1.0)
127
+ rack (>= 1.0, < 3)
128
+ rails (6.0.2)
129
+ actioncable (= 6.0.2)
130
+ actionmailbox (= 6.0.2)
131
+ actionmailer (= 6.0.2)
132
+ actionpack (= 6.0.2)
133
+ actiontext (= 6.0.2)
134
+ actionview (= 6.0.2)
135
+ activejob (= 6.0.2)
136
+ activemodel (= 6.0.2)
137
+ activerecord (= 6.0.2)
138
+ activestorage (= 6.0.2)
139
+ activesupport (= 6.0.2)
140
+ bundler (>= 1.3.0)
141
+ railties (= 6.0.2)
142
+ sprockets-rails (>= 2.0.0)
143
+ rails-dom-testing (2.0.3)
144
+ activesupport (>= 4.2.0)
145
+ nokogiri (>= 1.6)
146
+ rails-html-sanitizer (1.3.0)
147
+ loofah (~> 2.3)
148
+ railties (6.0.2)
149
+ actionpack (= 6.0.2)
150
+ activesupport (= 6.0.2)
151
+ method_source
152
+ rake (>= 0.8.7)
153
+ thor (>= 0.20.3, < 2.0)
154
+ rake (12.3.3)
155
+ redis (4.2.2)
156
+ redis-scripting (1.0.1)
157
+ redis (>= 3.0)
158
+ rspec (3.8.0)
159
+ rspec-core (~> 3.8.0)
160
+ rspec-expectations (~> 3.8.0)
161
+ rspec-mocks (~> 3.8.0)
162
+ rspec-core (3.8.2)
163
+ rspec-support (~> 3.8.0)
164
+ rspec-expectations (3.8.4)
165
+ diff-lcs (>= 1.2.0, < 2.0)
166
+ rspec-support (~> 3.8.0)
167
+ rspec-mocks (3.8.1)
168
+ diff-lcs (>= 1.2.0, < 2.0)
169
+ rspec-support (~> 3.8.0)
170
+ rspec-support (3.8.2)
171
+ sinatra (2.0.0.beta2)
172
+ mustermann (= 1.0.0.beta2)
173
+ rack (~> 2.0)
174
+ rack-protection (= 2.0.0.beta2)
175
+ tilt (~> 2.0)
176
+ sinatra-contrib (2.0.0.beta2)
177
+ backports (>= 2.0)
178
+ multi_json
179
+ mustermann (= 1.0.0.beta2)
180
+ rack-protection (= 2.0.0.beta2)
181
+ rack-test
182
+ sinatra (= 2.0.0.beta2)
183
+ tilt (>= 1.3, < 3)
184
+ sprockets (4.0.2)
185
+ concurrent-ruby (~> 1.0)
186
+ rack (> 1, < 3)
187
+ sprockets-rails (3.2.2)
188
+ actionpack (>= 4.0)
189
+ activesupport (>= 4.0)
190
+ sprockets (>= 3.0.0)
191
+ thor (1.0.1)
192
+ thread_safe (0.3.6)
193
+ tilt (2.0.9)
194
+ timecop (0.7.1)
195
+ tzinfo (1.2.7)
196
+ thread_safe (~> 0.1)
197
+ websocket-driver (0.7.3)
198
+ websocket-extensions (>= 0.1.0)
199
+ websocket-extensions (0.1.5)
200
+ wwtd (1.4.1)
201
+ zeitwerk (2.4.0)
202
+
203
+ PLATFORMS
204
+ ruby
205
+
206
+ DEPENDENCIES
207
+ bump
208
+ byebug
209
+ database_cleaner (= 1.6.1)
210
+ imperium (>= 0.5.2)
211
+ inst-jobs!
212
+ pg (< 1.0)
213
+ pry
214
+ rack-test
215
+ rails (~> 6.0.0)
216
+ rake
217
+ rspec (~> 3.8.0)
218
+ sinatra (= 2.0.0.beta2)
219
+ sinatra-contrib (= 2.0.0.beta2)
220
+ timecop (= 0.7.1)
221
+ wwtd (~> 1.4.0)
222
+
223
+ BUNDLED WITH
224
+ 2.1.2
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class AddStoryTable < ActiveRecord::Migration[4.2]
2
4
  def change
3
5
  create_table :stories do |table|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.expand_path("../spec_helper", __FILE__)
2
4
 
3
5
  describe 'Delayed::Backend::Redis::Job' do
@@ -5,10 +7,6 @@ describe 'Delayed::Backend::Redis::Job' do
5
7
  Delayed.select_backend(Delayed::Backend::Redis::Job)
6
8
  end
7
9
 
8
- after :all do
9
- Delayed.send(:remove_const, :Job)
10
- end
11
-
12
10
  before do
13
11
  Delayed::Testing.clear_all!
14
12
  end
@@ -18,8 +16,8 @@ describe 'Delayed::Backend::Redis::Job' do
18
16
  describe "tickle_strand" do
19
17
  it "should continue trying to tickle until the strand is empty" do
20
18
  jobs = []
21
- 3.times { jobs << "test".send_later_enqueue_args(:to_s, :strand => "s1", :no_delay => true) }
22
- job = "test".send_later_enqueue_args(:to_s, :strand => "s1", :no_delay => true)
19
+ 3.times { jobs << "test".delay(ignore_transaction: true, strand: "s1").to_s }
20
+ job = "test".delay(strand: "s1", ignore_transaction: true).to_s
23
21
  # manually delete the first jobs, bypassing the strand book-keeping
24
22
  jobs.each { |j| Delayed::Job.redis.del(Delayed::Job::Keys::JOB[j.id]) }
25
23
  Delayed::Job.redis.llen(Delayed::Job::Keys::STRAND['s1']).should == 4
@@ -29,8 +27,8 @@ describe 'Delayed::Backend::Redis::Job' do
29
27
 
30
28
  it "should tickle until it finds an existing job" do
31
29
  jobs = []
32
- 3.times { jobs << "test".send_later_enqueue_args(:to_s, :strand => "s1", :no_delay => true) }
33
- job = "test".send_later_enqueue_args(:to_s, :strand => "s1", :no_delay => true)
30
+ 3.times { jobs << "test".delay(strand: "s1", ignore_transaction: true).to_s }
31
+ job = "test".delay(strand: "s1", ignore_transaction: true).to_s
34
32
  # manually delete the first jobs, bypassing the strand book-keeping
35
33
  jobs[0...-1].each { |j| Delayed::Job.redis.del(Delayed::Job::Keys::JOB[j.id]) }
36
34
  Delayed::Job.redis.llen(Delayed::Job::Keys::STRAND['s1']).should == 4
@@ -44,8 +42,8 @@ describe 'Delayed::Backend::Redis::Job' do
44
42
 
45
43
  describe "missing jobs in queues" do
46
44
  before do
47
- @job = "test".send_later_enqueue_args(:to_s, :no_delay => true)
48
- @job2 = "test".send_later_enqueue_args(:to_s, :no_delay => true)
45
+ @job = "test".delay(ignore_transaction: true).to_s
46
+ @job2 = "test".delay(ignore_transaction: true).to_s
49
47
  # manually delete the job from redis
50
48
  Delayed::Job.redis.del(Delayed::Job::Keys::JOB[@job.id])
51
49
  end
@@ -63,11 +61,11 @@ describe 'Delayed::Backend::Redis::Job' do
63
61
  end
64
62
  end
65
63
 
66
- describe "send_later" do
64
+ describe "delay" do
67
65
  it "should schedule job on transaction commit" do
68
66
  before_count = Delayed::Job.jobs_count(:current)
69
67
  ActiveRecord::Base.transaction do
70
- job = "string".send_later :reverse
68
+ job = "string".delay.reverse
71
69
  job.should be_nil
72
70
  Delayed::Job.jobs_count(:current).should == before_count
73
71
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class SimpleJob
2
4
  cattr_accessor :runs; self.runs = 0
3
5
  def perform; @@runs += 1; end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_examples_for 'Delayed::Batch' do
2
4
  context "batching" do
3
5
  it "should batch up all deferrable delayed methods" do
4
6
  later = 1.hour.from_now
5
7
  Delayed::Batch.serial_batch {
6
- "string".send_later_enqueue_args(:size, no_delay: true).should be true
7
- "string".send_later_enqueue_args(:reverse, run_at: later, no_delay: true).should be_truthy # won't be batched, it'll get its own job
8
- "string".send_later_enqueue_args(:gsub, { no_delay: true }, /./, "!").should be_truthy
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
9
11
  }
10
12
  batch_jobs = Delayed::Job.find_available(5)
11
13
  regular_jobs = Delayed::Job.list_jobs(:future, 5)
@@ -24,8 +26,8 @@ shared_examples_for 'Delayed::Batch' do
24
26
  it "should not let you invoke it directly" do
25
27
  later = 1.hour.from_now
26
28
  Delayed::Batch.serial_batch {
27
- "string".send_later_enqueue_args(:size, no_delay: true).should be true
28
- "string".send_later_enqueue_args(:gsub, { no_delay: true }, /./, "!").should be true
29
+ "string".delay(ignore_transaction: true).size.should be true
30
+ "string".delay(ignore_transaction: true).gsub(/./, "!").should be true
29
31
  }
30
32
  Delayed::Job.jobs_count(:current).should == 1
31
33
  job = Delayed::Job.find_available(1).first
@@ -34,8 +36,8 @@ shared_examples_for 'Delayed::Batch' do
34
36
 
35
37
  it "should create valid jobs" do
36
38
  Delayed::Batch.serial_batch {
37
- "string".send_later_enqueue_args(:size, no_delay: true).should be true
38
- "string".send_later_enqueue_args(:gsub, { no_delay: true }, /./, "!").should be true
39
+ "string".delay(ignore_transaction: true).size.should be true
40
+ "string".delay(ignore_transaction: true).gsub(/./, "!").should be true
39
41
  }
40
42
  Delayed::Job.jobs_count(:current).should == 1
41
43
 
@@ -58,16 +60,16 @@ shared_examples_for 'Delayed::Batch' do
58
60
  it "should create a different batch for each priority" do
59
61
  later = 1.hour.from_now
60
62
  Delayed::Batch.serial_batch {
61
- "string".send_later_enqueue_args(:size, :priority => Delayed::LOW_PRIORITY, :no_delay => true).should be true
62
- "string".send_later_enqueue_args(:gsub, { :no_delay => true }, /./, "!").should be true
63
+ "string".delay(priority: Delayed::LOW_PRIORITY, ignore_transaction: true).size.should be true
64
+ "string".delay(ignore_transaction: true).gsub(/./, "!").should be true
63
65
  }
64
66
  Delayed::Job.jobs_count(:current).should == 2
65
67
  end
66
68
 
67
69
  it "should use the given priority for all, if specified" do
68
70
  Delayed::Batch.serial_batch(:priority => 11) {
69
- "string".send_later_enqueue_args(:size, :priority => 20, :no_delay => true).should be true
70
- "string".send_later_enqueue_args(:gsub, { :priority => 15, :no_delay => true }, /./, "!").should be true
71
+ "string".delay(priority: 20, ignore_transaction: true).size.should be true
72
+ "string".delay(priority: 15, ignore_transaction: true).gsub(/./, "!").should be true
71
73
  }
72
74
  Delayed::Job.jobs_count(:current).should == 1
73
75
  Delayed::Job.find_available(1).first.priority.should == 11
@@ -75,7 +77,7 @@ shared_examples_for 'Delayed::Batch' do
75
77
 
76
78
  it "should just create the job, if there's only one in the batch" do
77
79
  Delayed::Batch.serial_batch(:priority => 11) {
78
- "string".send_later_enqueue_args(:size, no_delay: true).should be true
80
+ "string".delay(ignore_transaction: true).size.should be true
79
81
  }
80
82
  Delayed::Job.jobs_count(:current).should == 1
81
83
  Delayed::Job.find_available(1).first.tag.should == "String#size"
@@ -84,9 +86,9 @@ shared_examples_for 'Delayed::Batch' do
84
86
 
85
87
  it "should list a job only once when the same call is made multiple times" do
86
88
  Delayed::Batch.serial_batch(:priority => 11) {
87
- "string".send_later_enqueue_args(:size, no_delay: true)
88
- "string".send_later_enqueue_args(:gsub, { no_delay: true }, /./, "!")
89
- "string".send_later_enqueue_args(:size, no_delay: true)
89
+ "string".delay(ignore_transaction: true).size
90
+ "string".delay(ignore_transaction: true).gsub(/./, "!")
91
+ "string".delay(ignore_transaction: true).size
90
92
  }
91
93
  batch_job = Delayed::Job.find_available(1).first
92
94
  jobs = batch_job.payload_object.jobs
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  shared_examples_for 'random ruby objects' do
2
4
  def set_queue(name)
3
5
  old_name = Delayed::Settings.queue
@@ -6,42 +8,42 @@ shared_examples_for 'random ruby objects' do
6
8
  Delayed::Settings.queue = old_name
7
9
  end
8
10
 
9
- it "should respond_to :send_later method" do
10
- Object.new.respond_to?(:send_later)
11
+ it "should respond_to :delay method" do
12
+ Object.new.respond_to?(:delay)
11
13
  end
12
14
 
13
- it "should raise a ArgumentError if send_later is called but the target method doesn't exist" do
14
- lambda { Object.new.send_later(:method_that_deos_not_exist) }.should raise_error(NoMethodError)
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)
15
17
  end
16
18
 
17
- it "should add a new entry to the job table when send_later is called on it" do
18
- lambda { Object.new.send_later(:to_s) }.should change { Delayed::Job.jobs_count(:current) }.by(1)
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)
19
21
  end
20
22
 
21
- it "should add a new entry to the job table when send_later_with_queue is called on it" do
22
- lambda { Object.new.send_later_with_queue(:to_s, "testqueue") }.should change { Delayed::Job.jobs_count(:current, "testqueue") }.by(1)
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)
23
25
  end
24
26
 
25
- it "should add a new entry to the job table when send_later is called on the class" do
26
- lambda { Object.send_later(:to_s) }.should change { Delayed::Job.jobs_count(:current) }.by(1)
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)
27
29
  end
28
30
 
29
- it "should add a new entry to the job table when send_later_with_queue is called on the class" do
30
- lambda { Object.send_later_with_queue(:to_s, "testqueue") }.should change { Delayed::Job.jobs_count(:current, "testqueue") }.by(1)
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)
31
33
  end
32
34
 
33
35
  context "class methods" do
34
- context "add_send_later_methods" do
36
+ context "handle_asynchronously" do
35
37
  it "should work with default_async" do
36
38
  klass = Class.new do
37
39
  attr_reader :ran
38
40
  def test_method; @ran = true; end
39
- add_send_later_methods :test_method, {}, true
41
+ handle_asynchronously :test_method
40
42
  end
41
43
  obj = klass.new
42
44
  lambda { obj.test_method }.should change { Delayed::Job.jobs_count(:current) }.by(1)
43
45
  obj.ran.should be_falsey
44
- lambda { obj.test_method_without_send_later }.should_not change { Delayed::Job.jobs_count(:current) }
46
+ lambda { obj.test_method(synchronous: true) }.should_not change { Delayed::Job.jobs_count(:current) }
45
47
  obj.ran.should be true
46
48
  end
47
49
 
@@ -49,7 +51,7 @@ shared_examples_for 'random ruby objects' do
49
51
  klass = Class.new do
50
52
  attr_reader :ran
51
53
  def test_method; @ran = true; end
52
- add_send_later_methods :test_method, {singleton: -> (obj) { "foobar:#{obj.object_id}" }}, true
54
+ handle_asynchronously :test_method, singleton: -> (obj) { "foobar:#{obj.object_id}" }
53
55
  end
54
56
 
55
57
  obj = klass.new
@@ -60,10 +62,10 @@ shared_examples_for 'random ruby objects' do
60
62
  klass = Class.new do
61
63
  attr_reader :run
62
64
  def test_method(my_kwarg: nil); @run = my_kwarg; end
63
- add_send_later_methods :test_method
65
+ handle_asynchronously :test_method
64
66
 
65
67
  def other_test(arg); @foo = arg; end
66
- add_send_later_methods :other_test
68
+ handle_asynchronously :other_test
67
69
  end
68
70
 
69
71
  obj = klass.new
@@ -71,117 +73,74 @@ shared_examples_for 'random ruby objects' do
71
73
  expect(obj.run).to eq 'foo'
72
74
  end
73
75
 
74
- it "should work without default_async" do
75
- klass = Class.new do
76
- attr_accessor :ran
77
- def test_method; @ran = true; end
78
- add_send_later_methods :test_method, {}, false
79
- end
80
- obj = klass.new
81
- lambda { obj.test_method }.should_not change { Delayed::Job.jobs_count(:current) }
82
- obj.ran.should be true
83
- obj.ran = false
84
- obj.ran.should be false
85
- lambda { obj.test_method_without_send_later }.should_not change { Delayed::Job.jobs_count(:current) }
86
- obj.ran.should be true
87
- end
88
-
89
- it "should send along enqueue args and args default async" do
76
+ it "should send along enqueue args and args" do
90
77
  klass = Class.new do
91
78
  attr_accessor :ran
92
79
  def test_method(*args); @ran = args; end
93
- add_send_later_methods(:test_method, {:enqueue_arg_1 => :thing}, true)
80
+ handle_asynchronously(:test_method, enqueue_arg_1: :thing)
94
81
  end
95
82
  obj = klass.new
96
83
  method = double()
97
84
 
98
- expect(Delayed::PerformableMethod).to receive(:new).with(obj, :test_method, [1,2,3, {synchronous: true}], nil, nil).and_return(method)
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)
99
86
  expect(Delayed::Job).to receive(:enqueue).with(method, :enqueue_arg_1 => :thing)
100
87
  obj.test_method(1,2,3)
101
88
 
102
- expect(Delayed::PerformableMethod).to receive(:new).with(obj, :test_method, [4, {:synchronous=>true}], nil, nil).and_return(method)
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)
103
90
  expect(Delayed::Job).to receive(:enqueue).with(method, :enqueue_arg_1 => :thing)
104
91
  obj.test_method(4)
105
92
 
106
93
  obj.ran.should be_nil
107
- obj.test_method_without_send_later(7)
94
+ obj.test_method(7, synchronous: true)
108
95
  obj.ran.should == [7]
109
96
  obj.ran = nil
110
97
  obj.ran.should == nil
111
- obj.test_method_without_send_later(8,9)
98
+ obj.test_method(8,9, synchronous: true)
112
99
  obj.ran.should == [8,9]
113
100
  end
114
101
 
115
- it "should handle punctuation correctly with default_async" do
102
+ it "should handle punctuation correctly" do
116
103
  klass = Class.new do
117
104
  attr_reader :ran
118
105
  def test_method?; @ran = true; end
119
- add_send_later_methods :test_method?, {}, true
106
+ handle_asynchronously :test_method?
120
107
  end
121
108
  obj = klass.new
122
109
  lambda { obj.test_method? }.should change { Delayed::Job.jobs_count(:current) }.by(1)
123
110
  obj.ran.should be_falsey
124
- lambda { obj.test_method_without_send_later? }.should_not change { Delayed::Job.jobs_count(:current) }
125
- obj.ran.should be true
126
- end
127
-
128
- it "should handle punctuation correctly without default_async" do
129
- klass = Class.new do
130
- attr_accessor :ran
131
- def test_method?; @ran = true; end
132
- add_send_later_methods :test_method?, {}, false
133
- end
134
- obj = klass.new
135
- lambda { obj.test_method? }.should_not change { Delayed::Job.jobs_count(:current) }
136
- obj.ran.should be true
137
- obj.ran = false
138
- obj.ran.should be false
139
- lambda { obj.test_method_without_send_later? }.should_not change { Delayed::Job.jobs_count(:current) }
111
+ lambda { obj.test_method?(synchronous: true) }.should_not change { Delayed::Job.jobs_count(:current) }
140
112
  obj.ran.should be true
141
113
  end
142
114
 
143
- it "should handle assignment punctuation correctly with default_async" do
115
+ it "should handle assignment punctuation correctly" do
144
116
  klass = Class.new do
145
117
  attr_reader :ran
146
118
  def test_method=(val); @ran = val; end
147
- add_send_later_methods :test_method=, {}, true
119
+ handle_asynchronously :test_method=
148
120
  end
149
121
  obj = klass.new
150
122
  lambda { obj.test_method = 3 }.should change { Delayed::Job.jobs_count(:current) }.by(1)
151
123
  obj.ran.should be_nil
152
- lambda { obj.test_method_without_send_later = 5 }.should_not change { Delayed::Job.jobs_count(:current) }
124
+ lambda { obj.send(:test_method=, 5, synchronous: true) }.should_not change { Delayed::Job.jobs_count(:current) }
153
125
  obj.ran.should == 5
154
126
  end
155
127
 
156
- it "should handle assignment punctuation correctly without default_async" do
157
- klass = Class.new do
158
- attr_accessor :ran
159
- def test_method=(val); @ran = val; end
160
- add_send_later_methods :test_method=, {}, false
161
- end
162
- obj = klass.new
163
- lambda { obj.test_method = 2 }.should_not change { Delayed::Job.jobs_count(:current) }
164
- obj.ran.should == 2
165
- lambda { obj.test_method_without_send_later = 3 }.should_not change { Delayed::Job.jobs_count(:current) }
166
- obj.ran.should == 3
167
- end
168
-
169
- it "should correctly sort out method accessibility with default async" do
128
+ it "should correctly sort out method accessibility" do
170
129
  klass1 = Class.new do
171
130
  def test_method; end
172
- add_send_later_methods :test_method, {}, true
131
+ handle_asynchronously :test_method
173
132
  end
174
133
 
175
134
  klass2 = Class.new do
176
135
  protected
177
136
  def test_method; end
178
- add_send_later_methods :test_method, {}, true
137
+ handle_asynchronously :test_method
179
138
  end
180
139
 
181
140
  klass3 = Class.new do
182
141
  private
183
142
  def test_method; end
184
- add_send_later_methods :test_method, {}, true
143
+ handle_asynchronously :test_method
185
144
  end
186
145
 
187
146
  klass1.public_method_defined?(:test_method).should be true
@@ -189,77 +148,6 @@ shared_examples_for 'random ruby objects' do
189
148
  klass3.private_method_defined?(:test_method).should be true
190
149
  end
191
150
  end
192
-
193
- context "handle_asynchonously_if_production" do
194
- it "should work in production" do
195
- expect(Rails.env).to receive(:production?).and_return(true)
196
- class TestObject; end
197
- expect(TestObject).to receive(:add_send_later_methods).with(:test_method, {}, true)
198
- class TestObject
199
- def test_method; end
200
- handle_asynchronously_if_production :test_method
201
- end
202
- end
203
-
204
- it "should work in other environments" do
205
- class TestObject; end
206
- expect(TestObject).to receive(:add_send_later_methods).with(:test_method, {}, false)
207
- class TestObject
208
- def test_method; end
209
- handle_asynchronously_if_production :test_method
210
- end
211
- end
212
-
213
- it "should pass along enqueue args in production" do
214
- expect(Rails.env).to receive(:production?).and_return(true)
215
- class TestObject; end
216
- expect(TestObject).to receive(:add_send_later_methods).with(:test_method, {:enqueue_arg_1 => true}, true)
217
- class TestObject
218
- def test_method; end
219
- handle_asynchronously_if_production :test_method, :enqueue_arg_1 => true
220
- end
221
- end
222
-
223
- it "should pass along enqueue args in other environments" do
224
- class TestObject; end
225
- expect(TestObject).to receive(:add_send_later_methods).with(:test_method, {:enqueue_arg_2 => "thing", :enqueue_arg_3 => 4}, false)
226
- class TestObject
227
- def test_method; end
228
- handle_asynchronously_if_production :test_method, :enqueue_arg_2 => "thing", :enqueue_arg_3 => 4
229
- end
230
- end
231
- end
232
-
233
- context "handle_asynchronously" do
234
- it "should work without enqueue_args" do
235
- class TestObject; end
236
- expect(TestObject).to receive(:add_send_later_methods).with(:test_method, {}, true)
237
- class TestObject
238
- def test_method; end
239
- handle_asynchronously :test_method
240
- end
241
- end
242
-
243
- it "should work with enqueue_args" do
244
- class TestObject; end
245
- expect(TestObject).to receive(:add_send_later_methods).with(:test_method, {:enqueue_arg_1 => :thing}, true)
246
- class TestObject
247
- def test_method; end
248
- handle_asynchronously :test_method, :enqueue_arg_1 => :thing
249
- end
250
- end
251
- end
252
-
253
- context "handle_asynchronously_with_queue" do
254
- it "should pass along the queue" do
255
- class TestObject; end
256
- expect(TestObject).to receive(:add_send_later_methods).with(:test_method, {:queue => "myqueue"}, true)
257
- class TestObject
258
- def test_method; end
259
- handle_asynchronously_with_queue :test_method, "myqueue"
260
- end
261
- end
262
- end
263
151
  end
264
152
 
265
153
  it "should call send later on methods which are wrapped with handle_asynchronously" do
@@ -270,30 +158,19 @@ shared_examples_for 'random ruby objects' do
270
158
  job = Delayed::Job.list_jobs(:current, 1).first
271
159
  job.payload_object.class.should == Delayed::PerformableMethod
272
160
  job.payload_object.method.should == :whatever
273
- job.payload_object.args.should == [1, 5, {:synchronous=>true}]
274
- job.payload_object.perform.should == 'Once upon...'
275
- end
276
-
277
- it "should call send later on methods which are wrapped with handle_asynchronously_with_queue" do
278
- story = Story.create :text => 'Once upon...'
279
-
280
- expect { story.whatever_else(1, 5) }.to change { Delayed::Job.jobs_count(:current, "testqueue") }.by(1)
281
-
282
- job = Delayed::Job.list_jobs(:current, 1, 0, "testqueue").first
283
- job.payload_object.class.should == Delayed::PerformableMethod
284
- job.payload_object.method.should == :whatever_else
285
- job.payload_object.args.should == [1, 5, {:synchronous=>true}]
161
+ job.payload_object.args.should == [1, 5]
162
+ job.payload_object.kwargs.should == {:synchronous=>true}
286
163
  job.payload_object.perform.should == 'Once upon...'
287
164
  end
288
165
 
289
- context "send_later" do
166
+ context "delay" do
290
167
  it "should use the default queue if there is one" do
291
168
  set_queue("testqueue") do
292
- "string".send_later :reverse
169
+ "string".delay.reverse
293
170
  job = Delayed::Job.list_jobs(:current, 1).first
294
171
  job.queue.should == "testqueue"
295
172
 
296
- "string".send_later :reverse, :queue => nil
173
+ "string".delay(queue: nil).reverse
297
174
  job2 = Delayed::Job.list_jobs(:current, 2).last
298
175
  job2.queue.should == "testqueue"
299
176
  end
@@ -304,22 +181,22 @@ shared_examples_for 'random ruby objects' do
304
181
  end
305
182
  end
306
183
 
307
- context "send_at" do
184
+ context "delay with run_at" do
308
185
  it "should queue a new job" do
309
186
  lambda do
310
- "string".send_at(1.hour.from_now, :length)
187
+ "string".delay(run_at: 1.hour.from_now).length
311
188
  end.should change { Delayed::Job.jobs_count(:future) }.by(1)
312
189
  end
313
190
 
314
191
  it "should schedule the job in the future" do
315
192
  time = 1.hour.from_now
316
- "string".send_at(time, :length)
193
+ "string".delay(run_at: time).length
317
194
  job = Delayed::Job.list_jobs(:future, 1).first
318
195
  job.run_at.to_i.should == time.to_i
319
196
  end
320
197
 
321
198
  it "should store payload as PerformableMethod" do
322
- "string".send_at(1.hour.from_now, :count, 'r')
199
+ "string".delay(run_at: 1.hour.from_now).count('r')
323
200
  job = Delayed::Job.list_jobs(:future, 1).first
324
201
  job.payload_object.class.should == Delayed::PerformableMethod
325
202
  job.payload_object.method.should == :count
@@ -329,46 +206,14 @@ shared_examples_for 'random ruby objects' do
329
206
 
330
207
  it "should use the default queue if there is one" do
331
208
  set_queue("testqueue") do
332
- "string".send_at 1.hour.from_now, :reverse
209
+ "string".delay(run_at: 1.hour.from_now).reverse
333
210
  job = Delayed::Job.list_jobs(:current, 1).first
334
211
  job.queue.should == "testqueue"
335
212
  end
336
213
  end
337
214
  end
338
215
 
339
- context "send_at_with_queue" do
340
- it "should queue a new job" do
341
- lambda do
342
- "string".send_at_with_queue(1.hour.from_now, :length, "testqueue")
343
- end.should change { Delayed::Job.jobs_count(:future, "testqueue") }.by(1)
344
- end
345
-
346
- it "should schedule the job in the future" do
347
- time = 1.hour.from_now
348
- "string".send_at_with_queue(time, :length, "testqueue")
349
- job = Delayed::Job.list_jobs(:future, 1, 0, "testqueue").first
350
- job.run_at.to_i.should == time.to_i
351
- end
352
-
353
- it "should override the default queue" do
354
- set_queue("default_queue") do
355
- "string".send_at_with_queue(1.hour.from_now, :length, "testqueue")
356
- job = Delayed::Job.list_jobs(:future, 1, 0, "testqueue").first
357
- job.queue.should == "testqueue"
358
- end
359
- end
360
-
361
- it "should store payload as PerformableMethod" do
362
- "string".send_at_with_queue(1.hour.from_now, :count, "testqueue", 'r')
363
- job = Delayed::Job.list_jobs(:future, 1, 0, "testqueue").first
364
- job.payload_object.class.should == Delayed::PerformableMethod
365
- job.payload_object.method.should == :count
366
- job.payload_object.args.should == ['r']
367
- job.payload_object.perform.should == 1
368
- end
369
- end
370
-
371
- describe "send_later_unless_in_job" do
216
+ describe "delay with synchronous argument" do
372
217
  module UnlessInJob
373
218
  @runs = 0
374
219
  def self.runs; @runs; end
@@ -378,7 +223,7 @@ shared_examples_for 'random ruby objects' do
378
223
  end
379
224
 
380
225
  def self.run_later
381
- self.send_later_unless_in_job :run
226
+ self.delay(synchronous: Delayed::Job.in_delayed_job?).run
382
227
  end
383
228
  end
384
229
 
@@ -387,7 +232,7 @@ shared_examples_for 'random ruby objects' do
387
232
  end
388
233
 
389
234
  it "should perform immediately if in job" do
390
- UnlessInJob.send_later :run_later
235
+ UnlessInJob.delay.run_later
391
236
  job = Delayed::Job.list_jobs(:current, 1).first
392
237
  job.invoke_job
393
238
  UnlessInJob.runs.should == 1