sidekiq 3.5.4 → 5.2.7

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sidekiq might be problematic. Click here for more details.

Files changed (175) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +61 -0
  3. data/{Contributing.md → .github/contributing.md} +0 -0
  4. data/.github/issue_template.md +11 -0
  5. data/.gitignore +3 -0
  6. data/.travis.yml +5 -10
  7. data/4.0-Upgrade.md +53 -0
  8. data/5.0-Upgrade.md +56 -0
  9. data/COMM-LICENSE +13 -11
  10. data/Changes.md +376 -1
  11. data/Ent-Changes.md +201 -2
  12. data/Gemfile +14 -18
  13. data/LICENSE +1 -1
  14. data/Pro-3.0-Upgrade.md +44 -0
  15. data/Pro-4.0-Upgrade.md +35 -0
  16. data/Pro-Changes.md +307 -2
  17. data/README.md +34 -22
  18. data/Rakefile +3 -3
  19. data/bin/sidekiq +0 -1
  20. data/bin/sidekiqctl +13 -86
  21. data/bin/sidekiqload +23 -27
  22. data/code_of_conduct.md +50 -0
  23. data/lib/generators/sidekiq/templates/worker_spec.rb.erb +3 -3
  24. data/lib/generators/sidekiq/templates/worker_test.rb.erb +6 -6
  25. data/lib/sidekiq.rb +72 -25
  26. data/lib/sidekiq/api.rb +206 -73
  27. data/lib/sidekiq/cli.rb +145 -101
  28. data/lib/sidekiq/client.rb +42 -36
  29. data/lib/sidekiq/core_ext.rb +1 -105
  30. data/lib/sidekiq/ctl.rb +221 -0
  31. data/lib/sidekiq/delay.rb +42 -0
  32. data/lib/sidekiq/exception_handler.rb +4 -5
  33. data/lib/sidekiq/extensions/action_mailer.rb +1 -0
  34. data/lib/sidekiq/extensions/active_record.rb +1 -0
  35. data/lib/sidekiq/extensions/class_methods.rb +1 -0
  36. data/lib/sidekiq/extensions/generic_proxy.rb +8 -1
  37. data/lib/sidekiq/fetch.rb +36 -111
  38. data/lib/sidekiq/job_logger.rb +25 -0
  39. data/lib/sidekiq/job_retry.rb +262 -0
  40. data/lib/sidekiq/launcher.rb +129 -55
  41. data/lib/sidekiq/logging.rb +21 -3
  42. data/lib/sidekiq/manager.rb +83 -182
  43. data/lib/sidekiq/middleware/chain.rb +1 -0
  44. data/lib/sidekiq/middleware/i18n.rb +1 -0
  45. data/lib/sidekiq/middleware/server/active_record.rb +10 -0
  46. data/lib/sidekiq/paginator.rb +1 -0
  47. data/lib/sidekiq/processor.rb +221 -103
  48. data/lib/sidekiq/rails.rb +47 -27
  49. data/lib/sidekiq/redis_connection.rb +74 -7
  50. data/lib/sidekiq/scheduled.rb +87 -28
  51. data/lib/sidekiq/testing.rb +150 -19
  52. data/lib/sidekiq/testing/inline.rb +1 -0
  53. data/lib/sidekiq/util.rb +15 -17
  54. data/lib/sidekiq/version.rb +2 -1
  55. data/lib/sidekiq/web.rb +120 -184
  56. data/lib/sidekiq/web/action.rb +89 -0
  57. data/lib/sidekiq/web/application.rb +353 -0
  58. data/lib/sidekiq/{web_helpers.rb → web/helpers.rb} +123 -47
  59. data/lib/sidekiq/web/router.rb +100 -0
  60. data/lib/sidekiq/worker.rb +135 -18
  61. data/sidekiq.gemspec +8 -14
  62. data/web/assets/images/{status-sd8051fd480.png → status.png} +0 -0
  63. data/web/assets/javascripts/application.js +24 -20
  64. data/web/assets/javascripts/dashboard.js +33 -18
  65. data/web/assets/stylesheets/application-rtl.css +246 -0
  66. data/web/assets/stylesheets/application.css +401 -7
  67. data/web/assets/stylesheets/bootstrap-rtl.min.css +9 -0
  68. data/web/assets/stylesheets/bootstrap.css +4 -8
  69. data/web/locales/ar.yml +81 -0
  70. data/web/locales/cs.yml +11 -1
  71. data/web/locales/de.yml +1 -1
  72. data/web/locales/en.yml +4 -0
  73. data/web/locales/es.yml +4 -3
  74. data/web/locales/fa.yml +80 -0
  75. data/web/locales/fr.yml +21 -12
  76. data/web/locales/he.yml +79 -0
  77. data/web/locales/ja.yml +24 -13
  78. data/web/locales/ru.yml +3 -0
  79. data/web/locales/ur.yml +80 -0
  80. data/web/views/_footer.erb +7 -9
  81. data/web/views/_job_info.erb +5 -1
  82. data/web/views/_nav.erb +5 -19
  83. data/web/views/_paging.erb +1 -1
  84. data/web/views/busy.erb +18 -9
  85. data/web/views/dashboard.erb +5 -5
  86. data/web/views/dead.erb +1 -1
  87. data/web/views/layout.erb +13 -5
  88. data/web/views/morgue.erb +16 -12
  89. data/web/views/queue.erb +12 -11
  90. data/web/views/queues.erb +5 -3
  91. data/web/views/retries.erb +19 -13
  92. data/web/views/retry.erb +2 -2
  93. data/web/views/scheduled.erb +4 -4
  94. data/web/views/scheduled_job_info.erb +1 -1
  95. metadata +45 -227
  96. data/lib/sidekiq/actor.rb +0 -39
  97. data/lib/sidekiq/middleware/server/logging.rb +0 -40
  98. data/lib/sidekiq/middleware/server/retry_jobs.rb +0 -206
  99. data/test/config.yml +0 -9
  100. data/test/env_based_config.yml +0 -11
  101. data/test/fake_env.rb +0 -0
  102. data/test/fixtures/en.yml +0 -2
  103. data/test/helper.rb +0 -49
  104. data/test/test_api.rb +0 -493
  105. data/test/test_cli.rb +0 -335
  106. data/test/test_client.rb +0 -194
  107. data/test/test_exception_handler.rb +0 -55
  108. data/test/test_extensions.rb +0 -126
  109. data/test/test_fetch.rb +0 -104
  110. data/test/test_logging.rb +0 -34
  111. data/test/test_manager.rb +0 -168
  112. data/test/test_middleware.rb +0 -159
  113. data/test/test_processor.rb +0 -237
  114. data/test/test_rails.rb +0 -21
  115. data/test/test_redis_connection.rb +0 -126
  116. data/test/test_retry.rb +0 -325
  117. data/test/test_scheduled.rb +0 -114
  118. data/test/test_scheduling.rb +0 -49
  119. data/test/test_sidekiq.rb +0 -99
  120. data/test/test_testing.rb +0 -142
  121. data/test/test_testing_fake.rb +0 -268
  122. data/test/test_testing_inline.rb +0 -93
  123. data/test/test_util.rb +0 -16
  124. data/test/test_web.rb +0 -608
  125. data/test/test_web_helpers.rb +0 -53
  126. data/web/assets/images/bootstrap/glyphicons-halflings-white.png +0 -0
  127. data/web/assets/images/bootstrap/glyphicons-halflings.png +0 -0
  128. data/web/assets/images/status/active.png +0 -0
  129. data/web/assets/images/status/idle.png +0 -0
  130. data/web/assets/javascripts/locales/README.md +0 -27
  131. data/web/assets/javascripts/locales/jquery.timeago.ar.js +0 -96
  132. data/web/assets/javascripts/locales/jquery.timeago.bg.js +0 -18
  133. data/web/assets/javascripts/locales/jquery.timeago.bs.js +0 -49
  134. data/web/assets/javascripts/locales/jquery.timeago.ca.js +0 -18
  135. data/web/assets/javascripts/locales/jquery.timeago.cs.js +0 -18
  136. data/web/assets/javascripts/locales/jquery.timeago.cy.js +0 -20
  137. data/web/assets/javascripts/locales/jquery.timeago.da.js +0 -18
  138. data/web/assets/javascripts/locales/jquery.timeago.de.js +0 -18
  139. data/web/assets/javascripts/locales/jquery.timeago.el.js +0 -18
  140. data/web/assets/javascripts/locales/jquery.timeago.en-short.js +0 -20
  141. data/web/assets/javascripts/locales/jquery.timeago.en.js +0 -20
  142. data/web/assets/javascripts/locales/jquery.timeago.es.js +0 -18
  143. data/web/assets/javascripts/locales/jquery.timeago.et.js +0 -18
  144. data/web/assets/javascripts/locales/jquery.timeago.fa.js +0 -22
  145. data/web/assets/javascripts/locales/jquery.timeago.fi.js +0 -28
  146. data/web/assets/javascripts/locales/jquery.timeago.fr-short.js +0 -16
  147. data/web/assets/javascripts/locales/jquery.timeago.fr.js +0 -17
  148. data/web/assets/javascripts/locales/jquery.timeago.he.js +0 -18
  149. data/web/assets/javascripts/locales/jquery.timeago.hr.js +0 -49
  150. data/web/assets/javascripts/locales/jquery.timeago.hu.js +0 -18
  151. data/web/assets/javascripts/locales/jquery.timeago.hy.js +0 -18
  152. data/web/assets/javascripts/locales/jquery.timeago.id.js +0 -18
  153. data/web/assets/javascripts/locales/jquery.timeago.it.js +0 -16
  154. data/web/assets/javascripts/locales/jquery.timeago.ja.js +0 -19
  155. data/web/assets/javascripts/locales/jquery.timeago.ko.js +0 -17
  156. data/web/assets/javascripts/locales/jquery.timeago.lt.js +0 -20
  157. data/web/assets/javascripts/locales/jquery.timeago.mk.js +0 -20
  158. data/web/assets/javascripts/locales/jquery.timeago.nl.js +0 -20
  159. data/web/assets/javascripts/locales/jquery.timeago.no.js +0 -18
  160. data/web/assets/javascripts/locales/jquery.timeago.pl.js +0 -31
  161. data/web/assets/javascripts/locales/jquery.timeago.pt-br.js +0 -16
  162. data/web/assets/javascripts/locales/jquery.timeago.pt.js +0 -16
  163. data/web/assets/javascripts/locales/jquery.timeago.ro.js +0 -18
  164. data/web/assets/javascripts/locales/jquery.timeago.rs.js +0 -49
  165. data/web/assets/javascripts/locales/jquery.timeago.ru.js +0 -34
  166. data/web/assets/javascripts/locales/jquery.timeago.sk.js +0 -18
  167. data/web/assets/javascripts/locales/jquery.timeago.sl.js +0 -44
  168. data/web/assets/javascripts/locales/jquery.timeago.sv.js +0 -18
  169. data/web/assets/javascripts/locales/jquery.timeago.th.js +0 -20
  170. data/web/assets/javascripts/locales/jquery.timeago.tr.js +0 -16
  171. data/web/assets/javascripts/locales/jquery.timeago.uk.js +0 -34
  172. data/web/assets/javascripts/locales/jquery.timeago.uz.js +0 -19
  173. data/web/assets/javascripts/locales/jquery.timeago.zh-cn.js +0 -20
  174. data/web/assets/javascripts/locales/jquery.timeago.zh-tw.js +0 -20
  175. data/web/views/_poll_js.erb +0 -5
@@ -1,325 +0,0 @@
1
- # encoding: utf-8
2
- require_relative 'helper'
3
- require 'sidekiq/scheduled'
4
- require 'sidekiq/middleware/server/retry_jobs'
5
-
6
- class TestRetry < Sidekiq::Test
7
- describe 'middleware' do
8
- class SomeWorker
9
- include Sidekiq::Worker
10
- end
11
-
12
- before do
13
- Sidekiq.redis {|c| c.flushdb }
14
- end
15
-
16
- def worker
17
- @worker ||= SomeWorker.new
18
- end
19
-
20
- def handler(options={})
21
- @handler ||= Sidekiq::Middleware::Server::RetryJobs.new(options)
22
- end
23
-
24
- def job(options={})
25
- @job ||= { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true }.merge(options)
26
- end
27
-
28
- it 'allows disabling retry' do
29
- assert_raises RuntimeError do
30
- handler.call(worker, job('retry' => false), 'default') do
31
- raise "kerblammo!"
32
- end
33
- end
34
- assert_equal 0, Sidekiq::RetrySet.new.size
35
- end
36
-
37
- it 'allows a numeric retry' do
38
- assert_raises RuntimeError do
39
- handler.call(worker, job('retry' => 2), 'default') do
40
- raise "kerblammo!"
41
- end
42
- end
43
- assert_equal 1, Sidekiq::RetrySet.new.size
44
- assert_equal 0, Sidekiq::DeadSet.new.size
45
- end
46
-
47
- it 'allows 0 retry => no retry and dead queue' do
48
- assert_raises RuntimeError do
49
- handler.call(worker, job('retry' => 0), 'default') do
50
- raise "kerblammo!"
51
- end
52
- end
53
- assert_equal 0, Sidekiq::RetrySet.new.size
54
- assert_equal 1, Sidekiq::DeadSet.new.size
55
- end
56
-
57
- it 'handles zany characters in error message, #1705' do
58
- skip 'skipped! test requires ruby 2.1+' if RUBY_VERSION <= '2.1.0'
59
-
60
- assert_raises RuntimeError do
61
- handler.call(worker, job, 'default') do
62
- raise "kerblammo! #{195.chr}"
63
- end
64
- end
65
- assert_equal "kerblammo! �", job["error_message"]
66
- end
67
-
68
-
69
- it 'allows a max_retries option in initializer' do
70
- max_retries = 7
71
- 1.upto(max_retries + 1) do
72
- assert_raises RuntimeError do
73
- handler(:max_retries => max_retries).call(worker, job, 'default') do
74
- raise "kerblammo!"
75
- end
76
- end
77
- end
78
-
79
- assert_equal max_retries, Sidekiq::RetrySet.new.size
80
- assert_equal 1, Sidekiq::DeadSet.new.size
81
- end
82
-
83
- it 'saves backtraces' do
84
- c = nil
85
- assert_raises RuntimeError do
86
- handler.call(worker, job('backtrace' => true), 'default') do
87
- c = caller(0); raise "kerblammo!"
88
- end
89
- end
90
- assert job["error_backtrace"]
91
- assert_equal c[0], job["error_backtrace"][0]
92
- end
93
-
94
- it 'saves partial backtraces' do
95
- c = nil
96
- assert_raises RuntimeError do
97
- handler.call(worker, job('backtrace' => 3), 'default') do
98
- c = caller(0)[0...3]; raise "kerblammo!"
99
- end
100
- end
101
- assert job["error_backtrace"]
102
- assert_equal c, job["error_backtrace"]
103
- assert_equal 3, c.size
104
- end
105
-
106
- it 'handles a new failed message' do
107
- assert_raises RuntimeError do
108
- handler.call(worker, job, 'default') do
109
- raise "kerblammo!"
110
- end
111
- end
112
- assert_equal 'default', job["queue"]
113
- assert_equal 'kerblammo!', job["error_message"]
114
- assert_equal 'RuntimeError', job["error_class"]
115
- assert_equal 0, job["retry_count"]
116
- refute job["error_backtrace"]
117
- assert job["failed_at"]
118
- end
119
-
120
- it 'shuts down without retrying work-in-progress, which will resume' do
121
- rs = Sidekiq::RetrySet.new
122
- assert_equal 0, rs.size
123
- msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true }
124
- assert_raises Sidekiq::Shutdown do
125
- handler.call(worker, msg, 'default') do
126
- raise Sidekiq::Shutdown
127
- end
128
- end
129
- assert_equal 0, rs.size
130
- end
131
-
132
- it 'shuts down cleanly when shutdown causes exception' do
133
- skip('Not supported in Ruby < 2.1.0') if RUBY_VERSION < '2.1.0'
134
-
135
- rs = Sidekiq::RetrySet.new
136
- assert_equal 0, rs.size
137
- msg = { 'class' => 'Bob', 'args' => [1,2,'foo'], 'retry' => true }
138
- assert_raises Sidekiq::Shutdown do
139
- handler.call(worker, msg, 'default') do
140
- begin
141
- raise Sidekiq::Shutdown
142
- rescue Interrupt
143
- raise "kerblammo!"
144
- end
145
- end
146
- end
147
- assert_equal 0, rs.size
148
- end
149
-
150
- it 'shuts down cleanly when shutdown causes chained exceptions' do
151
- skip('Not supported in Ruby < 2.1.0') if RUBY_VERSION < '2.1.0'
152
-
153
- rs = Sidekiq::RetrySet.new
154
- assert_equal 0, rs.size
155
- assert_raises Sidekiq::Shutdown do
156
- handler.call(worker, job, 'default') do
157
- begin
158
- raise Sidekiq::Shutdown
159
- rescue Interrupt
160
- begin
161
- raise "kerblammo!"
162
- rescue
163
- raise "kablooie!"
164
- end
165
- end
166
- end
167
- end
168
- assert_equal 0, rs.size
169
- end
170
-
171
- it 'allows a retry queue' do
172
- assert_raises RuntimeError do
173
- handler.call(worker, job("retry_queue" => 'retryx'), 'default') do
174
- raise "kerblammo!"
175
- end
176
- end
177
- assert_equal 'retryx', job["queue"]
178
- assert_equal 'kerblammo!', job["error_message"]
179
- assert_equal 'RuntimeError', job["error_class"]
180
- assert_equal 0, job["retry_count"]
181
- refute job["error_backtrace"]
182
- assert job["failed_at"]
183
- end
184
-
185
- it 'handles a recurring failed message' do
186
- now = Time.now.to_f
187
- msg = {"queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry_count"=>10}
188
- assert_raises RuntimeError do
189
- handler.call(worker, job(msg), 'default') do
190
- raise "kerblammo!"
191
- end
192
- end
193
- assert_equal 'default', job["queue"]
194
- assert_equal 'kerblammo!', job["error_message"]
195
- assert_equal 'RuntimeError', job["error_class"]
196
- assert_equal 11, job["retry_count"]
197
- assert job["failed_at"]
198
- end
199
-
200
- it 'throws away old messages after too many retries (using the default)' do
201
- q = Sidekiq::Queue.new
202
- rs = Sidekiq::RetrySet.new
203
- ds = Sidekiq::DeadSet.new
204
- assert_equal 0, q.size
205
- assert_equal 0, rs.size
206
- assert_equal 0, ds.size
207
- now = Time.now.to_f
208
- msg = {"queue"=>"default", "error_message"=>"kerblammo!", "error_class"=>"RuntimeError", "failed_at"=>now, "retry_count"=>25}
209
- assert_raises RuntimeError do
210
- handler.call(worker, job(msg), 'default') do
211
- raise "kerblammo!"
212
- end
213
- end
214
- assert_equal 0, q.size
215
- assert_equal 0, rs.size
216
- assert_equal 1, ds.size
217
- end
218
-
219
- describe "custom retry delay" do
220
- before do
221
- @old_logger = Sidekiq.logger
222
- @tmp_log_path = '/tmp/sidekiq-retries.log'
223
- Sidekiq.logger = Logger.new(@tmp_log_path)
224
- end
225
-
226
- after do
227
- Sidekiq.logger = @old_logger
228
- Sidekiq.options.delete(:logfile)
229
- File.unlink @tmp_log_path if File.exist?(@tmp_log_path)
230
- end
231
-
232
- class CustomWorkerWithoutException
233
- include Sidekiq::Worker
234
-
235
- sidekiq_retry_in do |count|
236
- count * 2
237
- end
238
- end
239
-
240
- class CustomWorkerWithException
241
- include Sidekiq::Worker
242
-
243
- sidekiq_retry_in do |count, exception|
244
- case exception
245
- when ArgumentError
246
- count * 4
247
- else
248
- count * 2
249
- end
250
- end
251
- end
252
-
253
- class ErrorWorker
254
- include Sidekiq::Worker
255
-
256
- sidekiq_retry_in do |count|
257
- count / 0
258
- end
259
- end
260
-
261
- it "retries with a default delay" do
262
- refute_equal 4, handler.__send__(:delay_for, worker, 2, StandardError.new)
263
- end
264
-
265
- it "retries with a custom delay and exception 1" do
266
- assert_equal 8, handler.__send__(:delay_for, CustomWorkerWithException, 2, ArgumentError.new)
267
- end
268
-
269
- it "retries with a custom delay and exception 2" do
270
- assert_equal 4, handler.__send__(:delay_for, CustomWorkerWithException, 2, StandardError.new)
271
- end
272
-
273
- it "retries with a custom delay without exception" do
274
- assert_equal 4, handler.__send__(:delay_for, CustomWorkerWithoutException, 2, StandardError.new)
275
- end
276
-
277
- it "falls back to the default retry on exception" do
278
- refute_equal 4, handler.__send__(:delay_for, ErrorWorker, 2, StandardError.new)
279
- assert_match(/Failure scheduling retry using the defined `sidekiq_retry_in`/,
280
- File.read(@tmp_log_path), 'Log entry missing for sidekiq_retry_in')
281
- end
282
- end
283
-
284
- describe 'handles errors withouth cause' do
285
- before do
286
- @error = nil
287
- begin
288
- raise ::StandardError, 'Error'
289
- rescue ::StandardError => e
290
- @error = e
291
- end
292
- end
293
-
294
- it "does not recurse infinitely checking if it's a shutdown" do
295
- assert(!Sidekiq::Middleware::Server::RetryJobs.new.send(
296
- :exception_caused_by_shutdown?, @error))
297
- end
298
- end
299
-
300
- describe 'handles errors with circular causes' do
301
- before do
302
- @error = nil
303
- begin
304
- begin
305
- raise ::StandardError, 'Error 1'
306
- rescue ::StandardError => e1
307
- begin
308
- raise ::StandardError, 'Error 2'
309
- rescue ::StandardError
310
- raise e1
311
- end
312
- end
313
- rescue ::StandardError => e
314
- @error = e
315
- end
316
- end
317
-
318
- it "does not recurse infinitely checking if it's a shutdown" do
319
- assert(!Sidekiq::Middleware::Server::RetryJobs.new.send(
320
- :exception_caused_by_shutdown?, @error))
321
- end
322
- end
323
- end
324
-
325
- end
@@ -1,114 +0,0 @@
1
- require_relative 'helper'
2
- require 'sidekiq/scheduled'
3
-
4
- class TestScheduled < Sidekiq::Test
5
- class ScheduledWorker
6
- include Sidekiq::Worker
7
- def perform(x)
8
- end
9
- end
10
-
11
- describe 'poller' do
12
- before do
13
- Sidekiq.redis{|c| c.flushdb}
14
- @error_1 = { 'class' => ScheduledWorker.name, 'args' => [0], 'queue' => 'queue_1' }
15
- @error_2 = { 'class' => ScheduledWorker.name, 'args' => [1], 'queue' => 'queue_2' }
16
- @error_3 = { 'class' => ScheduledWorker.name, 'args' => [2], 'queue' => 'queue_3' }
17
- @future_1 = { 'class' => ScheduledWorker.name, 'args' => [3], 'queue' => 'queue_4' }
18
- @future_2 = { 'class' => ScheduledWorker.name, 'args' => [4], 'queue' => 'queue_5' }
19
- @future_3 = { 'class' => ScheduledWorker.name, 'args' => [5], 'queue' => 'queue_6' }
20
-
21
- @retry = Sidekiq::RetrySet.new
22
- @scheduled = Sidekiq::ScheduledSet.new
23
- @poller = Sidekiq::Scheduled::Poller.new
24
- end
25
-
26
- class Stopper
27
- def call(worker_class, job, queue, r)
28
- yield if job['args'].first.odd?
29
- end
30
- end
31
-
32
- it 'executes client middleware' do
33
- Sidekiq.client_middleware.add Stopper
34
- begin
35
- @retry.schedule (Time.now - 60).to_f, @error_1
36
- @retry.schedule (Time.now - 60).to_f, @error_2
37
- @scheduled.schedule (Time.now - 60).to_f, @future_2
38
- @scheduled.schedule (Time.now - 60).to_f, @future_3
39
-
40
- @poller.poll
41
-
42
- assert_equal 0, Sidekiq::Queue.new("queue_1").size
43
- assert_equal 1, Sidekiq::Queue.new("queue_2").size
44
- assert_equal 0, Sidekiq::Queue.new("queue_5").size
45
- assert_equal 1, Sidekiq::Queue.new("queue_6").size
46
- ensure
47
- Sidekiq.client_middleware.remove Stopper
48
- end
49
- end
50
-
51
- it 'should empty the retry and scheduled queues up to the current time' do
52
- created_time = Time.new(2013, 2, 3)
53
- enqueued_time = Time.new(2013, 2, 4)
54
-
55
- Time.stub(:now, created_time) do
56
- @retry.schedule (enqueued_time - 60).to_f, @error_1.merge!('created_at' => created_time.to_f)
57
- @retry.schedule (enqueued_time - 50).to_f, @error_2.merge!('created_at' => created_time.to_f)
58
- @retry.schedule (enqueued_time + 60).to_f, @error_3.merge!('created_at' => created_time.to_f)
59
- @scheduled.schedule (enqueued_time - 60).to_f, @future_1.merge!('created_at' => created_time.to_f)
60
- @scheduled.schedule (enqueued_time - 50).to_f, @future_2.merge!('created_at' => created_time.to_f)
61
- @scheduled.schedule (enqueued_time + 60).to_f, @future_3.merge!('created_at' => created_time.to_f)
62
- end
63
-
64
- Time.stub(:now, enqueued_time) do
65
- @poller.poll
66
-
67
- Sidekiq.redis do |conn|
68
- %w(queue:queue_1 queue:queue_2 queue:queue_4 queue:queue_5).each do |queue_name|
69
- assert_equal 1, conn.llen(queue_name)
70
- job = Sidekiq.load_json(conn.lrange(queue_name, 0, -1)[0])
71
- assert_equal enqueued_time.to_f, job['enqueued_at']
72
- assert_equal created_time.to_f, job['created_at']
73
- end
74
- end
75
-
76
- assert_equal 1, @retry.size
77
- assert_equal 1, @scheduled.size
78
- end
79
- end
80
-
81
- def with_sidekiq_option(name, value)
82
- _original, Sidekiq.options[name] = Sidekiq.options[name], value
83
- begin
84
- yield
85
- ensure
86
- Sidekiq.options[name] = _original
87
- end
88
- end
89
-
90
- it 'generates random intervals that target a configured average' do
91
- with_sidekiq_option(:poll_interval_average, 10) do
92
- i = 500
93
- intervals = i.times.map{ @poller.send(:random_poll_interval) }
94
-
95
- assert intervals.all?{|x| x >= 5}
96
- assert intervals.all?{|x| x <= 15}
97
- assert_in_delta 10, intervals.reduce(&:+).to_f / i, 0.5
98
- end
99
- end
100
-
101
- it 'calculates an average poll interval based on the number of known Sidekiq processes' do
102
- with_sidekiq_option(:average_scheduled_poll_interval, 10) do
103
- 3.times do |i|
104
- Sidekiq.redis do |conn|
105
- conn.sadd("processes", "process-#{i}")
106
- conn.hset("process-#{i}", "info", nil)
107
- end
108
- end
109
-
110
- assert_equal 30, @poller.send(:scaled_poll_interval)
111
- end
112
- end
113
- end
114
- end
@@ -1,49 +0,0 @@
1
- require_relative 'helper'
2
- require 'sidekiq/scheduled'
3
-
4
- class TestScheduling < Sidekiq::Test
5
- describe 'middleware' do
6
- class ScheduledWorker
7
- include Sidekiq::Worker
8
- sidekiq_options :queue => :custom_queue
9
- def perform(x)
10
- end
11
- end
12
-
13
- it 'schedules jobs' do
14
- ss = Sidekiq::ScheduledSet.new
15
- ss.clear
16
-
17
- assert_equal 0, ss.size
18
-
19
- assert ScheduledWorker.perform_in(600, 'mike')
20
- assert_equal 1, ss.size
21
-
22
- assert ScheduledWorker.perform_in(1.month, 'mike')
23
- assert_equal 2, ss.size
24
-
25
- assert ScheduledWorker.perform_in(5.days.from_now, 'mike')
26
- assert_equal 3, ss.size
27
-
28
- q = Sidekiq::Queue.new("custom_queue")
29
- qs = q.size
30
- assert ScheduledWorker.perform_in(-300, 'mike')
31
- assert_equal 3, ss.size
32
- assert_equal qs+1, q.size
33
-
34
- assert Sidekiq::Client.push_bulk('class' => ScheduledWorker, 'args' => [['mike'], ['mike']], 'at' => 600)
35
- assert_equal 5, ss.size
36
- end
37
-
38
- it 'removes the enqueued_at field when scheduling' do
39
- ss = Sidekiq::ScheduledSet.new
40
- ss.clear
41
-
42
- assert ScheduledWorker.perform_in(1.month, 'mike')
43
- job = ss.first
44
- assert job['created_at']
45
- refute job['enqueued_at']
46
- end
47
- end
48
-
49
- end