inst-jobs 0.15.19 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) 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 +19 -7
  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/daemon.rb +2 -0
  35. data/lib/delayed/engine.rb +2 -0
  36. data/lib/delayed/job_tracking.rb +2 -0
  37. data/lib/delayed/lifecycle.rb +2 -0
  38. data/lib/delayed/log_tailer.rb +2 -0
  39. data/lib/delayed/logging.rb +2 -0
  40. data/lib/delayed/message_sending.rb +48 -111
  41. data/lib/delayed/performable_method.rb +15 -6
  42. data/lib/delayed/periodic.rb +6 -1
  43. data/lib/delayed/plugin.rb +2 -0
  44. data/lib/delayed/pool.rb +2 -0
  45. data/lib/delayed/server.rb +2 -0
  46. data/lib/delayed/server/helpers.rb +2 -0
  47. data/lib/delayed/settings.rb +7 -1
  48. data/lib/delayed/testing.rb +2 -0
  49. data/lib/delayed/version.rb +3 -1
  50. data/lib/delayed/work_queue/in_process.rb +2 -0
  51. data/lib/delayed/work_queue/parent_process.rb +2 -0
  52. data/lib/delayed/work_queue/parent_process/client.rb +2 -0
  53. data/lib/delayed/work_queue/parent_process/server.rb +3 -1
  54. data/lib/delayed/worker.rb +3 -1
  55. data/lib/delayed/worker/consul_health_check.rb +2 -0
  56. data/lib/delayed/worker/health_check.rb +2 -0
  57. data/lib/delayed/worker/null_health_check.rb +2 -0
  58. data/lib/delayed/worker/process_helper.rb +2 -0
  59. data/lib/delayed/yaml_extensions.rb +2 -0
  60. data/lib/delayed_job.rb +2 -0
  61. data/lib/inst-jobs.rb +2 -0
  62. data/spec/active_record_job_spec.rb +4 -2
  63. data/spec/delayed/cli_spec.rb +2 -0
  64. data/spec/delayed/daemon_spec.rb +2 -0
  65. data/spec/delayed/server_spec.rb +2 -0
  66. data/spec/delayed/settings_spec.rb +2 -0
  67. data/spec/delayed/work_queue/in_process_spec.rb +2 -0
  68. data/spec/delayed/work_queue/parent_process/client_spec.rb +2 -0
  69. data/spec/delayed/work_queue/parent_process/server_spec.rb +2 -0
  70. data/spec/delayed/work_queue/parent_process_spec.rb +2 -0
  71. data/spec/delayed/worker/consul_health_check_spec.rb +2 -0
  72. data/spec/delayed/worker/health_check_spec.rb +2 -0
  73. data/spec/delayed/worker_spec.rb +29 -0
  74. data/spec/gemfiles/51.gemfile.lock +7 -7
  75. data/spec/gemfiles/52.gemfile.lock +17 -15
  76. data/spec/gemfiles/60.gemfile.lock +91 -89
  77. data/spec/migrate/20140924140513_add_story_table.rb +2 -0
  78. data/spec/redis_job_spec.rb +10 -8
  79. data/spec/sample_jobs.rb +2 -0
  80. data/spec/shared/delayed_batch.rb +17 -15
  81. data/spec/shared/delayed_method.rb +49 -204
  82. data/spec/shared/performable_method.rb +11 -9
  83. data/spec/shared/shared_backend.rb +27 -25
  84. data/spec/shared/testing.rb +7 -5
  85. data/spec/shared/worker.rb +15 -13
  86. data/spec/shared_jobs_specs.rb +2 -0
  87. data/spec/spec_helper.rb +3 -1
  88. metadata +9 -7
@@ -1,98 +1,101 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- inst-jobs (0.15.12)
4
+ inst-jobs (1.0.0)
5
5
  activerecord (>= 4.2)
6
6
  activesupport (>= 4.2)
7
7
  after_transaction_commit (>= 1.0, < 3)
8
+ fugit (~> 1.3)
8
9
  railties (>= 4.2)
9
10
  redis (> 3.0)
10
11
  redis-scripting (~> 1.0.1)
11
- rufus-scheduler (~> 3.4, < 3.5)
12
12
 
13
13
  GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
- actioncable (6.0.0.rc2)
17
- actionpack (= 6.0.0.rc2)
16
+ actioncable (6.0.2)
17
+ actionpack (= 6.0.2)
18
18
  nio4r (~> 2.0)
19
19
  websocket-driver (>= 0.6.1)
20
- actionmailbox (6.0.0.rc2)
21
- actionpack (= 6.0.0.rc2)
22
- activejob (= 6.0.0.rc2)
23
- activerecord (= 6.0.0.rc2)
24
- activestorage (= 6.0.0.rc2)
25
- activesupport (= 6.0.0.rc2)
20
+ actionmailbox (6.0.2)
21
+ actionpack (= 6.0.2)
22
+ activejob (= 6.0.2)
23
+ activerecord (= 6.0.2)
24
+ activestorage (= 6.0.2)
25
+ activesupport (= 6.0.2)
26
26
  mail (>= 2.7.1)
27
- actionmailer (6.0.0.rc2)
28
- actionpack (= 6.0.0.rc2)
29
- actionview (= 6.0.0.rc2)
30
- activejob (= 6.0.0.rc2)
27
+ actionmailer (6.0.2)
28
+ actionpack (= 6.0.2)
29
+ actionview (= 6.0.2)
30
+ activejob (= 6.0.2)
31
31
  mail (~> 2.5, >= 2.5.4)
32
32
  rails-dom-testing (~> 2.0)
33
- actionpack (6.0.0.rc2)
34
- actionview (= 6.0.0.rc2)
35
- activesupport (= 6.0.0.rc2)
33
+ actionpack (6.0.2)
34
+ actionview (= 6.0.2)
35
+ activesupport (= 6.0.2)
36
36
  rack (~> 2.0)
37
37
  rack-test (>= 0.6.3)
38
38
  rails-dom-testing (~> 2.0)
39
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
40
- actiontext (6.0.0.rc2)
41
- actionpack (= 6.0.0.rc2)
42
- activerecord (= 6.0.0.rc2)
43
- activestorage (= 6.0.0.rc2)
44
- activesupport (= 6.0.0.rc2)
39
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
40
+ actiontext (6.0.2)
41
+ actionpack (= 6.0.2)
42
+ activerecord (= 6.0.2)
43
+ activestorage (= 6.0.2)
44
+ activesupport (= 6.0.2)
45
45
  nokogiri (>= 1.8.5)
46
- actionview (6.0.0.rc2)
47
- activesupport (= 6.0.0.rc2)
46
+ actionview (6.0.2)
47
+ activesupport (= 6.0.2)
48
48
  builder (~> 3.1)
49
49
  erubi (~> 1.4)
50
50
  rails-dom-testing (~> 2.0)
51
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
52
- activejob (6.0.0.rc2)
53
- activesupport (= 6.0.0.rc2)
51
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
52
+ activejob (6.0.2)
53
+ activesupport (= 6.0.2)
54
54
  globalid (>= 0.3.6)
55
- activemodel (6.0.0.rc2)
56
- activesupport (= 6.0.0.rc2)
57
- activerecord (6.0.0.rc2)
58
- activemodel (= 6.0.0.rc2)
59
- activesupport (= 6.0.0.rc2)
60
- activestorage (6.0.0.rc2)
61
- actionpack (= 6.0.0.rc2)
62
- activejob (= 6.0.0.rc2)
63
- activerecord (= 6.0.0.rc2)
55
+ activemodel (6.0.2)
56
+ activesupport (= 6.0.2)
57
+ activerecord (6.0.2)
58
+ activemodel (= 6.0.2)
59
+ activesupport (= 6.0.2)
60
+ activestorage (6.0.2)
61
+ actionpack (= 6.0.2)
62
+ activejob (= 6.0.2)
63
+ activerecord (= 6.0.2)
64
64
  marcel (~> 0.3.1)
65
- activesupport (6.0.0.rc2)
65
+ activesupport (6.0.2)
66
66
  concurrent-ruby (~> 1.0, >= 1.0.2)
67
67
  i18n (>= 0.7, < 2)
68
68
  minitest (~> 5.1)
69
69
  tzinfo (~> 1.1)
70
- zeitwerk (~> 2.1, >= 2.1.8)
71
- addressable (2.6.0)
72
- public_suffix (>= 2.0.2, < 4.0)
73
- after_transaction_commit (2.0.0)
74
- activerecord (>= 5.0)
70
+ zeitwerk (~> 2.2)
71
+ addressable (2.7.0)
72
+ public_suffix (>= 2.0.2, < 5.0)
73
+ after_transaction_commit (2.2.0)
74
+ activerecord (>= 5.2)
75
75
  backports (3.15.0)
76
- builder (3.2.3)
76
+ builder (3.2.4)
77
77
  bump (0.8.0)
78
78
  byebug (11.0.1)
79
79
  coderay (1.1.2)
80
- concurrent-ruby (1.1.5)
81
- crass (1.0.4)
80
+ concurrent-ruby (1.1.7)
81
+ crass (1.0.6)
82
82
  database_cleaner (1.6.1)
83
83
  diff-lcs (1.3)
84
- erubi (1.8.0)
85
- et-orbi (1.2.1)
84
+ erubi (1.9.0)
85
+ et-orbi (1.2.4)
86
86
  tzinfo
87
+ fugit (1.3.9)
88
+ et-orbi (~> 1.1, >= 1.1.8)
89
+ raabro (~> 1.3)
87
90
  globalid (0.4.2)
88
91
  activesupport (>= 4.2.0)
89
92
  httpclient (2.8.3)
90
- i18n (1.6.0)
93
+ i18n (1.8.5)
91
94
  concurrent-ruby (~> 1.0)
92
- imperium (0.5.1)
95
+ imperium (0.5.2)
93
96
  addressable (~> 2.5)
94
97
  httpclient (~> 2.8)
95
- loofah (2.2.3)
98
+ loofah (2.7.0)
96
99
  crass (~> 1.0.2)
97
100
  nokogiri (>= 1.5.9)
98
101
  mail (2.7.1)
@@ -100,53 +103,54 @@ GEM
100
103
  marcel (0.3.3)
101
104
  mimemagic (~> 0.3.2)
102
105
  method_source (0.9.2)
103
- mimemagic (0.3.3)
106
+ mimemagic (0.3.5)
104
107
  mini_mime (1.0.2)
105
108
  mini_portile2 (2.4.0)
106
- minitest (5.11.3)
109
+ minitest (5.14.2)
107
110
  multi_json (1.13.1)
108
111
  mustermann (1.0.0.beta2)
109
- nio4r (2.4.0)
110
- nokogiri (1.10.4)
112
+ nio4r (2.5.4)
113
+ nokogiri (1.10.10)
111
114
  mini_portile2 (~> 2.4.0)
112
115
  pg (0.21.0)
113
116
  pry (0.12.2)
114
117
  coderay (~> 1.1.0)
115
118
  method_source (~> 0.9.0)
116
- public_suffix (3.1.1)
119
+ public_suffix (4.0.6)
120
+ raabro (1.4.0)
117
121
  rack (2.0.7)
118
122
  rack-protection (2.0.0.beta2)
119
123
  rack
120
124
  rack-test (1.1.0)
121
125
  rack (>= 1.0, < 3)
122
- rails (6.0.0.rc2)
123
- actioncable (= 6.0.0.rc2)
124
- actionmailbox (= 6.0.0.rc2)
125
- actionmailer (= 6.0.0.rc2)
126
- actionpack (= 6.0.0.rc2)
127
- actiontext (= 6.0.0.rc2)
128
- actionview (= 6.0.0.rc2)
129
- activejob (= 6.0.0.rc2)
130
- activemodel (= 6.0.0.rc2)
131
- activerecord (= 6.0.0.rc2)
132
- activestorage (= 6.0.0.rc2)
133
- activesupport (= 6.0.0.rc2)
126
+ rails (6.0.2)
127
+ actioncable (= 6.0.2)
128
+ actionmailbox (= 6.0.2)
129
+ actionmailer (= 6.0.2)
130
+ actionpack (= 6.0.2)
131
+ actiontext (= 6.0.2)
132
+ actionview (= 6.0.2)
133
+ activejob (= 6.0.2)
134
+ activemodel (= 6.0.2)
135
+ activerecord (= 6.0.2)
136
+ activestorage (= 6.0.2)
137
+ activesupport (= 6.0.2)
134
138
  bundler (>= 1.3.0)
135
- railties (= 6.0.0.rc2)
139
+ railties (= 6.0.2)
136
140
  sprockets-rails (>= 2.0.0)
137
141
  rails-dom-testing (2.0.3)
138
142
  activesupport (>= 4.2.0)
139
143
  nokogiri (>= 1.6)
140
- rails-html-sanitizer (1.2.0)
141
- loofah (~> 2.2, >= 2.2.2)
142
- railties (6.0.0.rc2)
143
- actionpack (= 6.0.0.rc2)
144
- activesupport (= 6.0.0.rc2)
144
+ rails-html-sanitizer (1.3.0)
145
+ loofah (~> 2.3)
146
+ railties (6.0.2)
147
+ actionpack (= 6.0.2)
148
+ activesupport (= 6.0.2)
145
149
  method_source
146
150
  rake (>= 0.8.7)
147
151
  thor (>= 0.20.3, < 2.0)
148
152
  rake (12.3.3)
149
- redis (4.1.2)
153
+ redis (4.2.2)
150
154
  redis-scripting (1.0.1)
151
155
  redis (>= 3.0)
152
156
  rspec (3.8.0)
@@ -162,8 +166,6 @@ GEM
162
166
  diff-lcs (>= 1.2.0, < 2.0)
163
167
  rspec-support (~> 3.8.0)
164
168
  rspec-support (3.8.2)
165
- rufus-scheduler (3.4.2)
166
- et-orbi (~> 1.0)
167
169
  sinatra (2.0.0.beta2)
168
170
  mustermann (= 1.0.0.beta2)
169
171
  rack (~> 2.0)
@@ -177,24 +179,24 @@ GEM
177
179
  rack-test
178
180
  sinatra (= 2.0.0.beta2)
179
181
  tilt (>= 1.3, < 3)
180
- sprockets (3.7.2)
182
+ sprockets (4.0.2)
181
183
  concurrent-ruby (~> 1.0)
182
184
  rack (> 1, < 3)
183
- sprockets-rails (3.2.1)
185
+ sprockets-rails (3.2.2)
184
186
  actionpack (>= 4.0)
185
187
  activesupport (>= 4.0)
186
188
  sprockets (>= 3.0.0)
187
- thor (0.20.3)
189
+ thor (1.0.1)
188
190
  thread_safe (0.3.6)
189
191
  tilt (2.0.9)
190
192
  timecop (0.7.1)
191
- tzinfo (1.2.5)
193
+ tzinfo (1.2.7)
192
194
  thread_safe (~> 0.1)
193
- websocket-driver (0.7.1)
195
+ websocket-driver (0.7.3)
194
196
  websocket-extensions (>= 0.1.0)
195
- websocket-extensions (0.1.4)
196
- wwtd (1.3.0)
197
- zeitwerk (2.1.9)
197
+ websocket-extensions (0.1.5)
198
+ wwtd (1.4.1)
199
+ zeitwerk (2.4.0)
198
200
 
199
201
  PLATFORMS
200
202
  ruby
@@ -203,18 +205,18 @@ DEPENDENCIES
203
205
  bump
204
206
  byebug
205
207
  database_cleaner (= 1.6.1)
206
- imperium (>= 0.2.3)
208
+ imperium (>= 0.5.2)
207
209
  inst-jobs!
208
210
  pg (< 1.0)
209
211
  pry
210
212
  rack-test
211
- rails (= 6.0.0rc2)
213
+ rails (~> 6.0.0)
212
214
  rake
213
215
  rspec (~> 3.8.0)
214
216
  sinatra (= 2.0.0.beta2)
215
217
  sinatra-contrib (= 2.0.0.beta2)
216
218
  timecop (= 0.7.1)
217
- wwtd (~> 1.3.0)
219
+ wwtd (~> 1.4.0)
218
220
 
219
221
  BUNDLED WITH
220
- 2.0.2
222
+ 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
@@ -18,8 +20,8 @@ describe 'Delayed::Backend::Redis::Job' do
18
20
  describe "tickle_strand" do
19
21
  it "should continue trying to tickle until the strand is empty" do
20
22
  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)
23
+ 3.times { jobs << "test".delay(ignore_transaction: true, strand: "s1").to_s }
24
+ job = "test".delay(strand: "s1", ignore_transaction: true).to_s
23
25
  # manually delete the first jobs, bypassing the strand book-keeping
24
26
  jobs.each { |j| Delayed::Job.redis.del(Delayed::Job::Keys::JOB[j.id]) }
25
27
  Delayed::Job.redis.llen(Delayed::Job::Keys::STRAND['s1']).should == 4
@@ -29,8 +31,8 @@ describe 'Delayed::Backend::Redis::Job' do
29
31
 
30
32
  it "should tickle until it finds an existing job" do
31
33
  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)
34
+ 3.times { jobs << "test".delay(strand: "s1", ignore_transaction: true).to_s }
35
+ job = "test".delay(strand: "s1", ignore_transaction: true).to_s
34
36
  # manually delete the first jobs, bypassing the strand book-keeping
35
37
  jobs[0...-1].each { |j| Delayed::Job.redis.del(Delayed::Job::Keys::JOB[j.id]) }
36
38
  Delayed::Job.redis.llen(Delayed::Job::Keys::STRAND['s1']).should == 4
@@ -44,8 +46,8 @@ describe 'Delayed::Backend::Redis::Job' do
44
46
 
45
47
  describe "missing jobs in queues" do
46
48
  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)
49
+ @job = "test".delay(ignore_transaction: true).to_s
50
+ @job2 = "test".delay(ignore_transaction: true).to_s
49
51
  # manually delete the job from redis
50
52
  Delayed::Job.redis.del(Delayed::Job::Keys::JOB[@job.id])
51
53
  end
@@ -63,11 +65,11 @@ describe 'Delayed::Backend::Redis::Job' do
63
65
  end
64
66
  end
65
67
 
66
- describe "send_later" do
68
+ describe "delay" do
67
69
  it "should schedule job on transaction commit" do
68
70
  before_count = Delayed::Job.jobs_count(:current)
69
71
  ActiveRecord::Base.transaction do
70
- job = "string".send_later :reverse
72
+ job = "string".delay.reverse
71
73
  job.should be_nil
72
74
  Delayed::Job.jobs_count(:current).should == before_count
73
75
  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).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).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