sidekiq 3.4.1 → 4.0.2

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 (88) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/4.0-Upgrade.md +50 -0
  4. data/COMM-LICENSE +55 -45
  5. data/Changes.md +85 -1
  6. data/Ent-Changes.md +79 -0
  7. data/Gemfile +7 -1
  8. data/Pro-2.0-Upgrade.md +2 -2
  9. data/Pro-3.0-Upgrade.md +46 -0
  10. data/Pro-Changes.md +60 -2
  11. data/README.md +20 -16
  12. data/bin/sidekiq +4 -0
  13. data/bin/sidekiqctl +8 -2
  14. data/bin/sidekiqload +167 -0
  15. data/lib/generators/sidekiq/templates/worker_spec.rb.erb +2 -2
  16. data/lib/generators/sidekiq/templates/worker_test.rb.erb +5 -5
  17. data/lib/sidekiq/api.rb +43 -33
  18. data/lib/sidekiq/cli.rb +41 -42
  19. data/lib/sidekiq/client.rb +5 -10
  20. data/lib/sidekiq/fetch.rb +35 -111
  21. data/lib/sidekiq/launcher.rb +102 -42
  22. data/lib/sidekiq/manager.rb +80 -180
  23. data/lib/sidekiq/middleware/server/logging.rb +13 -8
  24. data/lib/sidekiq/middleware/server/retry_jobs.rb +6 -6
  25. data/lib/sidekiq/processor.rb +126 -97
  26. data/lib/sidekiq/redis_connection.rb +23 -5
  27. data/lib/sidekiq/scheduled.rb +47 -26
  28. data/lib/sidekiq/testing.rb +139 -17
  29. data/lib/sidekiq/util.rb +20 -0
  30. data/lib/sidekiq/version.rb +1 -1
  31. data/lib/sidekiq/web.rb +17 -1
  32. data/lib/sidekiq/web_helpers.rb +33 -5
  33. data/lib/sidekiq/worker.rb +16 -0
  34. data/lib/sidekiq.rb +37 -14
  35. data/sidekiq.gemspec +10 -11
  36. data/test/helper.rb +45 -10
  37. data/test/test_actors.rb +137 -0
  38. data/test/test_api.rb +417 -384
  39. data/test/test_cli.rb +29 -59
  40. data/test/test_client.rb +60 -135
  41. data/test/test_extensions.rb +29 -23
  42. data/test/test_fetch.rb +2 -57
  43. data/test/test_launcher.rb +80 -0
  44. data/test/test_logging.rb +1 -1
  45. data/test/test_manager.rb +16 -131
  46. data/test/test_middleware.rb +3 -5
  47. data/test/test_processor.rb +110 -76
  48. data/test/test_rails.rb +21 -0
  49. data/test/test_redis_connection.rb +0 -1
  50. data/test/test_retry.rb +114 -162
  51. data/test/test_scheduled.rb +11 -17
  52. data/test/test_scheduling.rb +20 -42
  53. data/test/test_sidekiq.rb +46 -16
  54. data/test/test_testing.rb +80 -20
  55. data/test/test_testing_fake.rb +83 -8
  56. data/test/test_testing_inline.rb +3 -3
  57. data/test/test_util.rb +16 -0
  58. data/test/test_web.rb +28 -9
  59. data/test/test_web_helpers.rb +3 -2
  60. data/web/assets/images/favicon.ico +0 -0
  61. data/web/assets/javascripts/application.js +6 -1
  62. data/web/assets/javascripts/dashboard.js +2 -8
  63. data/web/assets/javascripts/locales/jquery.timeago.pt-br.js +14 -14
  64. data/web/assets/stylesheets/application.css +33 -56
  65. data/web/locales/de.yml +1 -1
  66. data/web/locales/en.yml +2 -0
  67. data/web/locales/fr.yml +2 -2
  68. data/web/locales/ja.yml +10 -1
  69. data/web/locales/{no.yml → nb.yml} +10 -2
  70. data/web/locales/uk.yml +76 -0
  71. data/web/views/_footer.erb +2 -7
  72. data/web/views/_job_info.erb +5 -1
  73. data/web/views/_nav.erb +2 -2
  74. data/web/views/_poll_js.erb +5 -0
  75. data/web/views/{_poll.erb → _poll_link.erb} +0 -3
  76. data/web/views/busy.erb +2 -1
  77. data/web/views/dead.erb +1 -0
  78. data/web/views/layout.erb +2 -0
  79. data/web/views/morgue.erb +3 -0
  80. data/web/views/queue.erb +1 -0
  81. data/web/views/queues.erb +1 -0
  82. data/web/views/retries.erb +3 -0
  83. data/web/views/retry.erb +1 -0
  84. data/web/views/scheduled.erb +1 -0
  85. data/web/views/scheduled_job_info.erb +1 -0
  86. metadata +75 -55
  87. data/lib/sidekiq/actor.rb +0 -39
  88. data/test/test_worker_generator.rb +0 -17
data/test/test_testing.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require_relative 'helper'
2
- require 'sidekiq'
3
- require 'sidekiq/worker'
2
+
4
3
  require 'active_record'
5
4
  require 'action_mailer'
6
5
  require 'sidekiq/rails'
@@ -13,7 +12,7 @@ class TestTesting < Sidekiq::Test
13
12
  describe 'sidekiq testing' do
14
13
  describe 'require/load sidekiq/testing.rb' do
15
14
  before do
16
- require 'sidekiq/testing.rb'
15
+ require 'sidekiq/testing'
17
16
  end
18
17
 
19
18
  after do
@@ -22,37 +21,43 @@ class TestTesting < Sidekiq::Test
22
21
 
23
22
  it 'enables fake testing' do
24
23
  Sidekiq::Testing.fake!
25
- assert_equal true, Sidekiq::Testing.enabled?
26
- assert_equal true, Sidekiq::Testing.fake?
24
+ assert Sidekiq::Testing.enabled?
25
+ assert Sidekiq::Testing.fake?
26
+ refute Sidekiq::Testing.inline?
27
27
  end
28
28
 
29
29
  it 'enables fake testing in a block' do
30
30
  Sidekiq::Testing.disable!
31
- assert_equal true, Sidekiq::Testing.disabled?
31
+ assert Sidekiq::Testing.disabled?
32
+ refute Sidekiq::Testing.fake?
32
33
 
33
34
  Sidekiq::Testing.fake! do
34
- assert_equal true, Sidekiq::Testing.enabled?
35
- assert_equal true, Sidekiq::Testing.fake?
35
+ assert Sidekiq::Testing.enabled?
36
+ assert Sidekiq::Testing.fake?
37
+ refute Sidekiq::Testing.inline?
36
38
  end
37
39
 
38
- assert_equal false, Sidekiq::Testing.enabled?
39
- assert_equal false, Sidekiq::Testing.fake?
40
+ refute Sidekiq::Testing.enabled?
41
+ refute Sidekiq::Testing.fake?
40
42
  end
41
43
 
42
44
  it 'disables testing in a block' do
43
45
  Sidekiq::Testing.fake!
46
+ assert Sidekiq::Testing.fake?
44
47
 
45
48
  Sidekiq::Testing.disable! do
46
- assert_equal true, Sidekiq::Testing.disabled?
49
+ refute Sidekiq::Testing.fake?
50
+ assert Sidekiq::Testing.disabled?
47
51
  end
48
52
 
49
- assert_equal true, Sidekiq::Testing.enabled?
53
+ assert Sidekiq::Testing.fake?
54
+ assert Sidekiq::Testing.enabled?
50
55
  end
51
56
  end
52
57
 
53
58
  describe 'require/load sidekiq/testing/inline.rb' do
54
59
  before do
55
- require 'sidekiq/testing/inline.rb'
60
+ require 'sidekiq/testing/inline'
56
61
  end
57
62
 
58
63
  after do
@@ -61,22 +66,77 @@ class TestTesting < Sidekiq::Test
61
66
 
62
67
  it 'enables inline testing' do
63
68
  Sidekiq::Testing.inline!
64
- assert_equal true, Sidekiq::Testing.enabled?
65
- assert_equal true, Sidekiq::Testing.inline?
69
+ assert Sidekiq::Testing.enabled?
70
+ assert Sidekiq::Testing.inline?
71
+ refute Sidekiq::Testing.fake?
66
72
  end
67
73
 
68
74
  it 'enables inline testing in a block' do
69
75
  Sidekiq::Testing.disable!
70
- assert_equal true, Sidekiq::Testing.disabled?
76
+ assert Sidekiq::Testing.disabled?
77
+ refute Sidekiq::Testing.fake?
71
78
 
72
79
  Sidekiq::Testing.inline! do
73
- assert_equal true, Sidekiq::Testing.enabled?
74
- assert_equal true, Sidekiq::Testing.inline?
80
+ assert Sidekiq::Testing.enabled?
81
+ assert Sidekiq::Testing.inline?
75
82
  end
76
83
 
77
- assert_equal false, Sidekiq::Testing.enabled?
78
- assert_equal false, Sidekiq::Testing.inline?
84
+ refute Sidekiq::Testing.enabled?
85
+ refute Sidekiq::Testing.inline?
86
+ refute Sidekiq::Testing.fake?
79
87
  end
80
88
  end
81
89
  end
90
+
91
+ describe 'with middleware' do
92
+ before do
93
+ require 'sidekiq/testing'
94
+ end
95
+
96
+ after do
97
+ Sidekiq::Testing.disable!
98
+ end
99
+
100
+ class AttributeWorker
101
+ include Sidekiq::Worker
102
+ class_attribute :count
103
+ self.count = 0
104
+ attr_accessor :foo
105
+
106
+ def perform
107
+ self.class.count += 1 if foo == :bar
108
+ end
109
+ end
110
+
111
+ class AttributeMiddleware
112
+ def call(worker, msg, queue)
113
+ worker.foo = :bar if worker.respond_to?(:foo=)
114
+ yield
115
+ end
116
+ end
117
+
118
+ it 'wraps the inlined worker with middleware' do
119
+ Sidekiq::Testing.server_middleware do |chain|
120
+ chain.add AttributeMiddleware
121
+ end
122
+
123
+ begin
124
+ Sidekiq::Testing.fake! do
125
+ AttributeWorker.perform_async
126
+ assert_equal 0, AttributeWorker.count
127
+ end
128
+
129
+ AttributeWorker.perform_one
130
+ assert_equal 1, AttributeWorker.count
131
+
132
+ Sidekiq::Testing.inline! do
133
+ AttributeWorker.perform_async
134
+ assert_equal 2, AttributeWorker.count
135
+ end
136
+ ensure
137
+ Sidekiq::Testing.server_middleware.clear
138
+ end
139
+ end
140
+ end
141
+
82
142
  end
@@ -1,6 +1,5 @@
1
1
  require_relative 'helper'
2
- require 'sidekiq'
3
- require 'sidekiq/worker'
2
+
4
3
  require 'active_record'
5
4
  require 'action_mailer'
6
5
  require 'sidekiq/rails'
@@ -47,7 +46,7 @@ class TestTesting < Sidekiq::Test
47
46
  end
48
47
 
49
48
  before do
50
- require 'sidekiq/testing.rb'
49
+ require 'sidekiq/testing'
51
50
  Sidekiq::Testing.fake!
52
51
  EnqueuedWorker.jobs.clear
53
52
  DirectWorker.jobs.clear
@@ -55,6 +54,7 @@ class TestTesting < Sidekiq::Test
55
54
 
56
55
  after do
57
56
  Sidekiq::Testing.disable!
57
+ Sidekiq::Queues.clear_all
58
58
  end
59
59
 
60
60
  it 'stubs the async call' do
@@ -94,7 +94,7 @@ class TestTesting < Sidekiq::Test
94
94
  it 'stubs the enqueue_to call' do
95
95
  assert_equal 0, EnqueuedWorker.jobs.size
96
96
  assert Sidekiq::Client.enqueue_to('someq', EnqueuedWorker, 1, 2)
97
- assert_equal 1, EnqueuedWorker.jobs.size
97
+ assert_equal 1, Sidekiq::Queues['someq'].size
98
98
  end
99
99
 
100
100
  it 'executes all stored jobs' do
@@ -106,7 +106,6 @@ class TestTesting < Sidekiq::Test
106
106
  StoredWorker.drain
107
107
  end
108
108
  assert_equal 0, StoredWorker.jobs.size
109
-
110
109
  end
111
110
 
112
111
  class SpecificJidWorker
@@ -263,9 +262,85 @@ class TestTesting < Sidekiq::Test
263
262
  end
264
263
 
265
264
  it 'can execute a job' do
266
- worker = Minitest::Mock.new
267
- worker.expect(:perform, nil, [1, 2, 3])
268
- DirectWorker.execute_job(worker, [1, 2, 3])
265
+ DirectWorker.execute_job(DirectWorker.new, [2, 3])
266
+ end
267
+ end
268
+
269
+ describe 'queue testing' do
270
+ before do
271
+ require 'sidekiq/testing'
272
+ Sidekiq::Testing.fake!
273
+ end
274
+
275
+ after do
276
+ Sidekiq::Testing.disable!
277
+ Sidekiq::Queues.clear_all
278
+ end
279
+
280
+ class QueueWorker
281
+ include Sidekiq::Worker
282
+ def perform(a, b)
283
+ a + b
284
+ end
285
+ end
286
+
287
+ class AltQueueWorker
288
+ include Sidekiq::Worker
289
+ sidekiq_options queue: :alt
290
+ def perform(a, b)
291
+ a + b
292
+ end
293
+ end
294
+
295
+ it 'finds enqueued jobs' do
296
+ assert_equal 0, Sidekiq::Queues["default"].size
297
+
298
+ QueueWorker.perform_async(1, 2)
299
+ QueueWorker.perform_async(1, 2)
300
+ AltQueueWorker.perform_async(1, 2)
301
+
302
+ assert_equal 2, Sidekiq::Queues["default"].size
303
+ assert_equal [1, 2], Sidekiq::Queues["default"].first["args"]
304
+
305
+ assert_equal 1, Sidekiq::Queues["alt"].size
306
+ end
307
+
308
+ it 'clears out all queues' do
309
+ assert_equal 0, Sidekiq::Queues["default"].size
310
+
311
+ QueueWorker.perform_async(1, 2)
312
+ QueueWorker.perform_async(1, 2)
313
+ AltQueueWorker.perform_async(1, 2)
314
+
315
+ Sidekiq::Queues.clear_all
316
+
317
+ assert_equal 0, Sidekiq::Queues["default"].size
318
+ assert_equal 0, QueueWorker.jobs.size
319
+ assert_equal 0, Sidekiq::Queues["alt"].size
320
+ assert_equal 0, AltQueueWorker.jobs.size
321
+ end
322
+
323
+ it 'finds jobs enqueued by client' do
324
+ Sidekiq::Client.push(
325
+ 'class' => 'NonExistentWorker',
326
+ 'queue' => 'missing',
327
+ 'args' => [1]
328
+ )
329
+
330
+ assert_equal 1, Sidekiq::Queues["missing"].size
331
+ end
332
+
333
+ it 'respects underlying array changes' do
334
+ # Rspec expect change() syntax saves a reference to
335
+ # an underlying array. When the array containing jobs is
336
+ # derived, Rspec test using `change(QueueWorker.jobs, :size).by(1)`
337
+ # won't pass. This attempts to recreate that scenario
338
+ # by saving a reference to the jobs array and ensuring
339
+ # it changes properly on enqueueing
340
+ jobs = QueueWorker.jobs
341
+ assert_equal 0, jobs.size
342
+ QueueWorker.perform_async(1, 2)
343
+ assert_equal 1, jobs.size
269
344
  end
270
345
  end
271
346
  end
@@ -1,6 +1,5 @@
1
1
  require_relative 'helper'
2
- require 'sidekiq'
3
- require 'sidekiq/worker'
2
+
4
3
  require 'active_record'
5
4
  require 'action_mailer'
6
5
  require 'sidekiq/rails'
@@ -42,7 +41,7 @@ class TestInline < Sidekiq::Test
42
41
  end
43
42
 
44
43
  before do
45
- require 'sidekiq/testing/inline.rb'
44
+ require 'sidekiq/testing/inline'
46
45
  Sidekiq::Testing.inline!
47
46
  end
48
47
 
@@ -89,5 +88,6 @@ class TestInline < Sidekiq::Test
89
88
  it 'should relay parameters through json' do
90
89
  assert Sidekiq::Client.enqueue(InlineWorkerWithTimeParam, Time.now)
91
90
  end
91
+
92
92
  end
93
93
  end
data/test/test_util.rb ADDED
@@ -0,0 +1,16 @@
1
+ require_relative 'helper'
2
+
3
+ class TestUtil < Sidekiq::Test
4
+
5
+ class Helpers
6
+ include Sidekiq::Util
7
+ end
8
+
9
+ def test_hertz_donut
10
+ obj = Helpers.new
11
+ output = capture_logging(Logger::DEBUG) do
12
+ assert_equal false, obj.want_a_hertz_donut?
13
+ end
14
+ assert_includes output, "hz: 10"
15
+ end
16
+ end
data/test/test_web.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # encoding: utf-8
2
2
  require_relative 'helper'
3
- require 'sidekiq'
4
3
  require 'sidekiq/web'
5
4
  require 'rack/test'
5
+ require 'tilt/erubis'
6
6
 
7
7
  class TestWeb < Sidekiq::Test
8
8
 
@@ -18,7 +18,6 @@ class TestWeb < Sidekiq::Test
18
18
  end
19
19
 
20
20
  before do
21
- Sidekiq.redis = REDIS
22
21
  Sidekiq.redis {|c| c.flushdb }
23
22
  end
24
23
 
@@ -40,6 +39,15 @@ class TestWeb < Sidekiq::Test
40
39
  rackenv = {'HTTP_ACCEPT_LANGUAGE' => 'en-us'}
41
40
  get '/', {}, rackenv
42
41
  assert_match(/Dashboard/, last_response.body)
42
+ rackenv = {'HTTP_ACCEPT_LANGUAGE' => 'zh-cn'}
43
+ get '/', {}, rackenv
44
+ assert_match(/信息板/, last_response.body)
45
+ rackenv = {'HTTP_ACCEPT_LANGUAGE' => 'zh-tw'}
46
+ get '/', {}, rackenv
47
+ assert_match(/資訊主頁/, last_response.body)
48
+ rackenv = {'HTTP_ACCEPT_LANGUAGE' => 'nb'}
49
+ get '/', {}, rackenv
50
+ assert_match(/Oversikt/, last_response.body)
43
51
  end
44
52
 
45
53
  describe 'busy' do
@@ -292,7 +300,13 @@ class TestWeb < Sidekiq::Test
292
300
 
293
301
  get '/queues/default'
294
302
  assert_equal 200, last_response.status
295
- assert_match /#{msg['args'][2]}/, last_response.body
303
+ assert_match(/#{msg['args'][2]}/, last_response.body)
304
+ end
305
+
306
+ it 'calls updatePage() once when polling' do
307
+ get '/busy?poll=true'
308
+ assert_equal 200, last_response.status
309
+ assert_equal 1, last_response.body.scan('updatePage(').count
296
310
  end
297
311
 
298
312
  it 'escape job args and error messages' do
@@ -355,19 +369,24 @@ class TestWeb < Sidekiq::Test
355
369
  assert_equal 200, last_response.status
356
370
  end
357
371
 
358
- Sidekiq::Web.settings.locales << File.join(File.dirname(__FILE__), "fixtures")
359
- it 'can show user defined tab with custom locales' do
360
- begin
372
+ describe 'custom locales' do
373
+ before do
374
+ Sidekiq::Web.settings.locales << File.join(File.dirname(__FILE__), "fixtures")
361
375
  Sidekiq::Web.tabs['Custom Tab'] = '/custom'
362
376
  Sidekiq::Web.get('/custom') do
377
+ clear_caches # ugly hack since I can't figure out how to access WebHelpers outside of this context
363
378
  t('translated_text')
364
379
  end
380
+ end
381
+
382
+ after do
383
+ Sidekiq::Web.tabs.delete 'Custom Tab'
384
+ Sidekiq::Web.settings.locales.pop
385
+ end
365
386
 
387
+ it 'can show user defined tab with custom locales' do
366
388
  get '/custom'
367
389
  assert_match(/Changed text/, last_response.body)
368
-
369
- ensure
370
- Sidekiq::Web.tabs.delete 'Custom Tab'
371
390
  end
372
391
  end
373
392
 
@@ -1,6 +1,4 @@
1
1
  require_relative 'helper'
2
- require 'sidekiq'
3
- require 'sidekiq/web_helpers'
4
2
 
5
3
  class TestWebHelpers < Sidekiq::Test
6
4
 
@@ -43,6 +41,9 @@ class TestWebHelpers < Sidekiq::Test
43
41
  obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4,ru;q=0.2')
44
42
  assert_equal 'zh-cn', obj.locale
45
43
 
44
+ obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'nb-NO,nb;q=0.2')
45
+ assert_equal 'nb', obj.locale
46
+
46
47
  obj = Helpers.new('HTTP_ACCEPT_LANGUAGE' => 'en-us; *')
47
48
  assert_equal 'en', obj.locale
48
49
 
Binary file
@@ -58,9 +58,14 @@ function updatePage(url) {
58
58
  url: url,
59
59
  dataType: 'html'
60
60
  }).done(function (data) {
61
- var $page = $(data).filter('#page')
61
+ $data = $(data)
62
+
63
+ var $page = $data.filter('#page')
62
64
  $('#page').replaceWith($page)
63
65
 
66
+ var $header_status = $data.find('.status')
67
+ $('.status').replaceWith($header_status)
68
+
64
69
  $("time").timeago()
65
70
  })
66
71
  }, parseInt(localStorage.timeInterval) || 2000);
@@ -227,14 +227,8 @@ var updateRedisStats = function(data) {
227
227
  }
228
228
 
229
229
  var pulseBeacon = function(){
230
- $beacon = $('.beacon')
231
- $beacon.find('.dot').addClass('pulse').delay(1000).queue(function(){
232
- $(this).removeClass('pulse');
233
- $(this).dequeue();
234
- });
235
- $beacon.find('.ring').addClass('pulse').delay(1000).queue(function(){
236
- $(this).removeClass('pulse');
237
- $(this).dequeue();
230
+ $('.beacon').addClass('pulse').delay(1000).queue(function(){
231
+ $(this).removeClass('pulse').dequeue();
238
232
  });
239
233
  }
240
234
 
@@ -1,16 +1,16 @@
1
- // Brazilian Portuguese
1
+ // Brasilian Portuguese
2
2
  jQuery.timeago.settings.strings = {
3
3
  suffixAgo: "atrás",
4
- suffixFromNow: "nesse momento",
5
- seconds: "alguns segundos",
6
- minute: " um minuto",
7
- minutes: "%d minutos",
8
- hour: " uma hora",
9
- hours: " %d horas",
10
- day: "um dia",
11
- days: "%d dias",
12
- month: " um mês",
13
- months: "%d meses",
14
- year: " um ano",
15
- years: "%d anos"
16
- };
4
+ suffixFromNow: "a partir de agora",
5
+ seconds: "menos de um minuto",
6
+ minute: "cerca de um minuto",
7
+ minutes: "%d minutos",
8
+ hour: "cerca de uma hora",
9
+ hours: "cerca de %d horas",
10
+ day: "um dia",
11
+ days: "%d dias",
12
+ month: "cerca de um mês",
13
+ months: "%d meses",
14
+ year: "cerca de um ano",
15
+ years: "%d anos"
16
+ };