sidekiq 4.2.4 → 5.2.0
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.
- checksums.yaml +4 -4
- data/.github/issue_template.md +8 -1
- data/.gitignore +1 -0
- data/.travis.yml +5 -3
- data/5.0-Upgrade.md +56 -0
- data/COMM-LICENSE +1 -1
- data/Changes.md +151 -0
- data/Ent-Changes.md +77 -2
- data/Gemfile +10 -25
- data/LICENSE +1 -1
- data/Pro-4.0-Upgrade.md +35 -0
- data/Pro-Changes.md +156 -2
- data/README.md +9 -6
- data/Rakefile +1 -2
- data/bin/sidekiqctl +1 -1
- data/bin/sidekiqload +15 -33
- data/lib/generators/sidekiq/templates/worker_spec.rb.erb +1 -1
- data/lib/generators/sidekiq/templates/worker_test.rb.erb +1 -1
- data/lib/sidekiq/api.rb +157 -67
- data/lib/sidekiq/cli.rb +71 -26
- data/lib/sidekiq/client.rb +25 -18
- data/lib/sidekiq/core_ext.rb +1 -106
- data/lib/sidekiq/delay.rb +42 -0
- data/lib/sidekiq/exception_handler.rb +2 -4
- data/lib/sidekiq/extensions/generic_proxy.rb +7 -1
- data/lib/sidekiq/fetch.rb +1 -1
- data/lib/sidekiq/job_logger.rb +25 -0
- data/lib/sidekiq/job_retry.rb +241 -0
- data/lib/sidekiq/launcher.rb +45 -37
- data/lib/sidekiq/logging.rb +18 -2
- data/lib/sidekiq/manager.rb +3 -4
- data/lib/sidekiq/middleware/server/active_record.rb +10 -0
- data/lib/sidekiq/processor.rb +91 -34
- data/lib/sidekiq/rails.rb +15 -51
- data/lib/sidekiq/redis_connection.rb +31 -5
- data/lib/sidekiq/scheduled.rb +35 -8
- data/lib/sidekiq/testing.rb +24 -7
- data/lib/sidekiq/util.rb +6 -2
- data/lib/sidekiq/version.rb +1 -1
- data/lib/sidekiq/web/action.rb +2 -6
- data/lib/sidekiq/web/application.rb +28 -21
- data/lib/sidekiq/web/helpers.rb +67 -23
- data/lib/sidekiq/web/router.rb +14 -10
- data/lib/sidekiq/web.rb +4 -4
- data/lib/sidekiq/worker.rb +97 -14
- data/lib/sidekiq.rb +23 -24
- data/sidekiq.gemspec +7 -10
- data/web/assets/javascripts/application.js +0 -0
- data/web/assets/javascripts/dashboard.js +18 -13
- data/web/assets/stylesheets/application-rtl.css +246 -0
- data/web/assets/stylesheets/application.css +336 -4
- data/web/assets/stylesheets/bootstrap-rtl.min.css +9 -0
- data/web/assets/stylesheets/bootstrap.css +2 -2
- data/web/locales/ar.yml +80 -0
- data/web/locales/en.yml +1 -0
- data/web/locales/es.yml +4 -3
- data/web/locales/fa.yml +80 -0
- data/web/locales/he.yml +79 -0
- data/web/locales/ja.yml +5 -3
- data/web/locales/ur.yml +80 -0
- data/web/views/_footer.erb +5 -2
- data/web/views/_job_info.erb +1 -1
- data/web/views/_nav.erb +1 -1
- data/web/views/_paging.erb +1 -1
- data/web/views/busy.erb +9 -5
- data/web/views/dashboard.erb +3 -3
- data/web/views/layout.erb +11 -2
- data/web/views/morgue.erb +14 -10
- data/web/views/queue.erb +10 -10
- data/web/views/queues.erb +4 -2
- data/web/views/retries.erb +13 -11
- data/web/views/retry.erb +1 -1
- data/web/views/scheduled.erb +2 -2
- metadata +26 -160
- data/lib/sidekiq/middleware/server/logging.rb +0 -40
- data/lib/sidekiq/middleware/server/retry_jobs.rb +0 -205
- data/test/config.yml +0 -9
- data/test/env_based_config.yml +0 -11
- data/test/fake_env.rb +0 -1
- data/test/fixtures/en.yml +0 -2
- data/test/helper.rb +0 -75
- data/test/test_actors.rb +0 -138
- data/test/test_api.rb +0 -528
- data/test/test_cli.rb +0 -418
- data/test/test_client.rb +0 -266
- data/test/test_exception_handler.rb +0 -56
- data/test/test_extensions.rb +0 -127
- data/test/test_fetch.rb +0 -50
- data/test/test_launcher.rb +0 -95
- data/test/test_logging.rb +0 -35
- data/test/test_manager.rb +0 -50
- data/test/test_middleware.rb +0 -158
- data/test/test_processor.rb +0 -235
- data/test/test_rails.rb +0 -22
- data/test/test_redis_connection.rb +0 -132
- data/test/test_retry.rb +0 -326
- data/test/test_retry_exhausted.rb +0 -149
- data/test/test_scheduled.rb +0 -115
- data/test/test_scheduling.rb +0 -58
- data/test/test_sidekiq.rb +0 -107
- data/test/test_testing.rb +0 -143
- data/test/test_testing_fake.rb +0 -357
- data/test/test_testing_inline.rb +0 -94
- data/test/test_util.rb +0 -13
- data/test/test_web.rb +0 -726
- data/test/test_web_helpers.rb +0 -54
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require_relative 'helper'
|
3
|
-
require 'sidekiq/exception_handler'
|
4
|
-
require 'stringio'
|
5
|
-
require 'logger'
|
6
|
-
|
7
|
-
ExceptionHandlerTestException = Class.new(StandardError)
|
8
|
-
TEST_EXCEPTION = ExceptionHandlerTestException.new("Something didn't work!")
|
9
|
-
|
10
|
-
class Component
|
11
|
-
include Sidekiq::ExceptionHandler
|
12
|
-
|
13
|
-
def invoke_exception(args)
|
14
|
-
raise TEST_EXCEPTION
|
15
|
-
rescue ExceptionHandlerTestException => e
|
16
|
-
handle_exception(e,args)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class TestExceptionHandler < Sidekiq::Test
|
21
|
-
describe "with mock logger" do
|
22
|
-
before do
|
23
|
-
@old_logger = Sidekiq.logger
|
24
|
-
@str_logger = StringIO.new
|
25
|
-
Sidekiq.logger = Logger.new(@str_logger)
|
26
|
-
end
|
27
|
-
|
28
|
-
after do
|
29
|
-
Sidekiq.logger = @old_logger
|
30
|
-
end
|
31
|
-
|
32
|
-
it "logs the exception to Sidekiq.logger" do
|
33
|
-
Component.new.invoke_exception(:a => 1)
|
34
|
-
@str_logger.rewind
|
35
|
-
log = @str_logger.readlines
|
36
|
-
assert_match(/"a":1/, log[0], "didn't include the context")
|
37
|
-
assert_match(/Something didn't work!/, log[1], "didn't include the exception message")
|
38
|
-
assert_match(/test\/test_exception_handler.rb/, log[2], "didn't include the backtrace")
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "when the exception does not have a backtrace" do
|
42
|
-
it "does not fail" do
|
43
|
-
exception = ExceptionHandlerTestException.new
|
44
|
-
assert_nil exception.backtrace
|
45
|
-
|
46
|
-
begin
|
47
|
-
Component.new.handle_exception exception
|
48
|
-
pass
|
49
|
-
rescue StandardError
|
50
|
-
flunk "failed handling a nil backtrace"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
data/test/test_extensions.rb
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require_relative 'helper'
|
3
|
-
require 'sidekiq'
|
4
|
-
require 'active_record'
|
5
|
-
require 'action_mailer'
|
6
|
-
require 'sidekiq/extensions/action_mailer'
|
7
|
-
require 'sidekiq/extensions/active_record'
|
8
|
-
require 'sidekiq/rails'
|
9
|
-
|
10
|
-
Sidekiq.hook_rails!
|
11
|
-
|
12
|
-
class TestExtensions < Sidekiq::Test
|
13
|
-
describe 'sidekiq extensions' do
|
14
|
-
before do
|
15
|
-
Sidekiq.redis = REDIS
|
16
|
-
Sidekiq.redis {|c| c.flushdb }
|
17
|
-
end
|
18
|
-
|
19
|
-
class MyModel < ActiveRecord::Base
|
20
|
-
def self.long_class_method
|
21
|
-
raise "Should not be called!"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'allows delayed execution of ActiveRecord class methods' do
|
26
|
-
assert_equal [], Sidekiq::Queue.all.map(&:name)
|
27
|
-
q = Sidekiq::Queue.new
|
28
|
-
assert_equal 0, q.size
|
29
|
-
MyModel.delay.long_class_method
|
30
|
-
assert_equal ['default'], Sidekiq::Queue.all.map(&:name)
|
31
|
-
assert_equal 1, q.size
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'uses and stringifies specified options' do
|
35
|
-
assert_equal [], Sidekiq::Queue.all.map(&:name)
|
36
|
-
q = Sidekiq::Queue.new('notdefault')
|
37
|
-
assert_equal 0, q.size
|
38
|
-
MyModel.delay(queue: :notdefault).long_class_method
|
39
|
-
assert_equal ['notdefault'], Sidekiq::Queue.all.map(&:name)
|
40
|
-
assert_equal 1, q.size
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'allows delayed scheduling of AR class methods' do
|
44
|
-
ss = Sidekiq::ScheduledSet.new
|
45
|
-
assert_equal 0, ss.size
|
46
|
-
MyModel.delay_for(5.days).long_class_method
|
47
|
-
assert_equal 1, ss.size
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'allows until delayed scheduling of AR class methods' do
|
51
|
-
ss = Sidekiq::ScheduledSet.new
|
52
|
-
assert_equal 0, ss.size
|
53
|
-
MyModel.delay_until(1.day.from_now).long_class_method
|
54
|
-
assert_equal 1, ss.size
|
55
|
-
end
|
56
|
-
|
57
|
-
class UserMailer < ActionMailer::Base
|
58
|
-
def greetings(a, b)
|
59
|
-
raise "Should not be called!"
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'allows delayed delivery of ActionMailer mails' do
|
64
|
-
assert_equal [], Sidekiq::Queue.all.map(&:name)
|
65
|
-
q = Sidekiq::Queue.new
|
66
|
-
assert_equal 0, q.size
|
67
|
-
UserMailer.delay.greetings(1, 2)
|
68
|
-
assert_equal ['default'], Sidekiq::Queue.all.map(&:name)
|
69
|
-
assert_equal 1, q.size
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'allows delayed scheduling of AM mails' do
|
73
|
-
ss = Sidekiq::ScheduledSet.new
|
74
|
-
assert_equal 0, ss.size
|
75
|
-
UserMailer.delay_for(5.days).greetings(1, 2)
|
76
|
-
assert_equal 1, ss.size
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'allows until delay scheduling of AM mails' do
|
80
|
-
ss = Sidekiq::ScheduledSet.new
|
81
|
-
assert_equal 0, ss.size
|
82
|
-
UserMailer.delay_until(5.days.from_now).greetings(1, 2)
|
83
|
-
assert_equal 1, ss.size
|
84
|
-
end
|
85
|
-
|
86
|
-
class SomeClass
|
87
|
-
def self.doit(arg)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'allows delay of any ole class method' do
|
92
|
-
q = Sidekiq::Queue.new
|
93
|
-
assert_equal 0, q.size
|
94
|
-
SomeClass.delay.doit(Date.today)
|
95
|
-
assert_equal 1, q.size
|
96
|
-
end
|
97
|
-
|
98
|
-
module SomeModule
|
99
|
-
def self.doit(arg)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'allows delay of any module class method' do
|
104
|
-
q = Sidekiq::Queue.new
|
105
|
-
assert_equal 0, q.size
|
106
|
-
SomeModule.delay.doit(Date.today)
|
107
|
-
assert_equal 1, q.size
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'allows removing of the #delay methods' do
|
111
|
-
q = Sidekiq::Queue.new
|
112
|
-
Sidekiq.remove_delay!
|
113
|
-
assert_equal 0, q.size
|
114
|
-
assert_raises NoMethodError do
|
115
|
-
SomeModule.delay.doit(Date.today)
|
116
|
-
end
|
117
|
-
|
118
|
-
Sidekiq.instance_eval { remove_instance_variable :@delay_removed }
|
119
|
-
# Reload modified modules
|
120
|
-
load 'sidekiq/extensions/action_mailer.rb'
|
121
|
-
load 'sidekiq/extensions/active_record.rb'
|
122
|
-
load 'sidekiq/extensions/generic_proxy.rb'
|
123
|
-
load 'sidekiq/extensions/class_methods.rb'
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
data/test/test_fetch.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require_relative 'helper'
|
3
|
-
require 'sidekiq/fetch'
|
4
|
-
|
5
|
-
class TestFetcher < Sidekiq::Test
|
6
|
-
describe 'fetcher' do
|
7
|
-
before do
|
8
|
-
Sidekiq.redis = { :url => REDIS_URL, :namespace => 'fuzzy' }
|
9
|
-
Sidekiq.redis do |conn|
|
10
|
-
conn.flushdb
|
11
|
-
conn.rpush('queue:basic', 'msg')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
after do
|
16
|
-
Sidekiq.redis = REDIS
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'retrieves' do
|
20
|
-
fetch = Sidekiq::BasicFetch.new(:queues => ['basic', 'bar'])
|
21
|
-
uow = fetch.retrieve_work
|
22
|
-
refute_nil uow
|
23
|
-
assert_equal 'basic', uow.queue_name
|
24
|
-
assert_equal 'msg', uow.job
|
25
|
-
q = Sidekiq::Queue.new('basic')
|
26
|
-
assert_equal 0, q.size
|
27
|
-
uow.requeue
|
28
|
-
assert_equal 1, q.size
|
29
|
-
assert_nil uow.acknowledge
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'retrieves with strict setting' do
|
33
|
-
fetch = Sidekiq::BasicFetch.new(:queues => ['basic', 'bar', 'bar'], :strict => true)
|
34
|
-
cmd = fetch.queues_cmd
|
35
|
-
assert_equal cmd, ['queue:basic', 'queue:bar', Sidekiq::BasicFetch::TIMEOUT]
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'bulk requeues' do
|
39
|
-
q1 = Sidekiq::Queue.new('foo')
|
40
|
-
q2 = Sidekiq::Queue.new('bar')
|
41
|
-
assert_equal 0, q1.size
|
42
|
-
assert_equal 0, q2.size
|
43
|
-
uow = Sidekiq::BasicFetch::UnitOfWork
|
44
|
-
Sidekiq::BasicFetch.bulk_requeue([uow.new('fuzzy:queue:foo', 'bob'), uow.new('fuzzy:queue:foo', 'bar'), uow.new('fuzzy:queue:bar', 'widget')], {:queues => []})
|
45
|
-
assert_equal 2, q1.size
|
46
|
-
assert_equal 1, q2.size
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
data/test/test_launcher.rb
DELETED
@@ -1,95 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require_relative 'helper'
|
3
|
-
require 'sidekiq/launcher'
|
4
|
-
|
5
|
-
class TestLauncher < Sidekiq::Test
|
6
|
-
|
7
|
-
describe 'launcher' do
|
8
|
-
before do
|
9
|
-
Sidekiq.redis {|c| c.flushdb }
|
10
|
-
end
|
11
|
-
|
12
|
-
def new_manager(opts)
|
13
|
-
Sidekiq::Manager.new(opts)
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'heartbeat' do
|
17
|
-
before do
|
18
|
-
@mgr = new_manager(options)
|
19
|
-
@launcher = Sidekiq::Launcher.new(options)
|
20
|
-
@launcher.manager = @mgr
|
21
|
-
|
22
|
-
Sidekiq::Processor::WORKER_STATE['a'] = {'b' => 1}
|
23
|
-
|
24
|
-
@proctitle = $0
|
25
|
-
end
|
26
|
-
|
27
|
-
after do
|
28
|
-
Sidekiq::Processor::WORKER_STATE.clear
|
29
|
-
$0 = @proctitle
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'fires new heartbeat events' do
|
33
|
-
i = 0
|
34
|
-
Sidekiq.on(:heartbeat) do
|
35
|
-
i += 1
|
36
|
-
end
|
37
|
-
assert_equal 0, i
|
38
|
-
@launcher.heartbeat('identity', heartbeat_data, Sidekiq.dump_json(heartbeat_data))
|
39
|
-
assert_equal 1, i
|
40
|
-
@launcher.heartbeat('identity', heartbeat_data, Sidekiq.dump_json(heartbeat_data))
|
41
|
-
assert_equal 1, i
|
42
|
-
end
|
43
|
-
|
44
|
-
describe 'when manager is active' do
|
45
|
-
before do
|
46
|
-
Sidekiq::CLI::PROCTITLES << proc { "xyz" }
|
47
|
-
@launcher.heartbeat('identity', heartbeat_data, Sidekiq.dump_json(heartbeat_data))
|
48
|
-
Sidekiq::CLI::PROCTITLES.pop
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'sets useful info to proctitle' do
|
52
|
-
assert_equal "sidekiq #{Sidekiq::VERSION} myapp [1 of 3 busy] xyz", $0
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'stores process info in redis' do
|
56
|
-
info = Sidekiq.redis { |c| c.hmget('identity', 'busy') }
|
57
|
-
assert_equal ["1"], info
|
58
|
-
expires = Sidekiq.redis { |c| c.pttl('identity') }
|
59
|
-
assert_in_delta 60000, expires, 500
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
describe 'when manager is stopped' do
|
64
|
-
before do
|
65
|
-
@launcher.quiet
|
66
|
-
@launcher.heartbeat('identity', heartbeat_data, Sidekiq.dump_json(heartbeat_data))
|
67
|
-
end
|
68
|
-
|
69
|
-
#after do
|
70
|
-
#puts system('redis-cli -n 15 keys "*" | while read LINE ; do TTL=`redis-cli -n 15 ttl "$LINE"`; if [ "$TTL" -eq -1 ]; then echo "$LINE"; fi; done;')
|
71
|
-
#end
|
72
|
-
|
73
|
-
it 'indicates stopping status in proctitle' do
|
74
|
-
assert_equal "sidekiq #{Sidekiq::VERSION} myapp [1 of 3 busy] stopping", $0
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'stores process info in redis' do
|
78
|
-
info = Sidekiq.redis { |c| c.hmget('identity', 'busy') }
|
79
|
-
assert_equal ["1"], info
|
80
|
-
expires = Sidekiq.redis { |c| c.pttl('identity') }
|
81
|
-
assert_in_delta 60000, expires, 50
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def options
|
87
|
-
{ :concurrency => 3, :queues => ['default'] }
|
88
|
-
end
|
89
|
-
|
90
|
-
def heartbeat_data
|
91
|
-
{ 'concurrency' => 3, 'tag' => 'myapp' }
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
data/test/test_logging.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require_relative 'helper'
|
3
|
-
require 'sidekiq/logging'
|
4
|
-
|
5
|
-
class TestLogging < Sidekiq::Test
|
6
|
-
describe Sidekiq::Logging do
|
7
|
-
describe "#with_context" do
|
8
|
-
def context
|
9
|
-
Sidekiq::Logging.logger.formatter.context
|
10
|
-
end
|
11
|
-
|
12
|
-
it "has no context by default" do
|
13
|
-
context.must_equal nil
|
14
|
-
end
|
15
|
-
|
16
|
-
it "can add a context" do
|
17
|
-
Sidekiq::Logging.with_context "xx" do
|
18
|
-
context.must_equal " xx"
|
19
|
-
end
|
20
|
-
context.must_equal nil
|
21
|
-
end
|
22
|
-
|
23
|
-
it "can use multiple contexts" do
|
24
|
-
Sidekiq::Logging.with_context "xx" do
|
25
|
-
context.must_equal " xx"
|
26
|
-
Sidekiq::Logging.with_context "yy" do
|
27
|
-
context.must_equal " xx yy"
|
28
|
-
end
|
29
|
-
context.must_equal " xx"
|
30
|
-
end
|
31
|
-
context.must_equal nil
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/test/test_manager.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require_relative 'helper'
|
3
|
-
require 'sidekiq/manager'
|
4
|
-
|
5
|
-
class TestManager < Sidekiq::Test
|
6
|
-
|
7
|
-
describe 'manager' do
|
8
|
-
before do
|
9
|
-
Sidekiq.redis {|c| c.flushdb }
|
10
|
-
end
|
11
|
-
|
12
|
-
def new_manager(opts)
|
13
|
-
Sidekiq::Manager.new(opts)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'creates N processor instances' do
|
17
|
-
mgr = new_manager(options)
|
18
|
-
assert_equal options[:concurrency], mgr.workers.size
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'shuts down the system' do
|
22
|
-
mgr = new_manager(options)
|
23
|
-
mgr.stop(Time.now)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'throws away dead processors' do
|
27
|
-
mgr = new_manager(options)
|
28
|
-
init_size = mgr.workers.size
|
29
|
-
processor = mgr.workers.first
|
30
|
-
begin
|
31
|
-
mgr.processor_died(processor, 'ignored')
|
32
|
-
|
33
|
-
assert_equal init_size, mgr.workers.size
|
34
|
-
refute mgr.workers.include?(processor)
|
35
|
-
ensure
|
36
|
-
mgr.workers.each {|p| p.terminate(true) }
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'does not support invalid concurrency' do
|
41
|
-
assert_raises(ArgumentError) { new_manager(concurrency: 0) }
|
42
|
-
assert_raises(ArgumentError) { new_manager(concurrency: -1) }
|
43
|
-
end
|
44
|
-
|
45
|
-
def options
|
46
|
-
{ :concurrency => 3, :queues => ['default'] }
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
data/test/test_middleware.rb
DELETED
@@ -1,158 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require_relative 'helper'
|
3
|
-
require 'sidekiq/middleware/chain'
|
4
|
-
require 'sidekiq/processor'
|
5
|
-
|
6
|
-
class TestMiddleware < Sidekiq::Test
|
7
|
-
describe 'middleware chain' do
|
8
|
-
before do
|
9
|
-
$errors = []
|
10
|
-
Sidekiq.redis = REDIS
|
11
|
-
end
|
12
|
-
|
13
|
-
class CustomMiddleware
|
14
|
-
def initialize(name, recorder)
|
15
|
-
@name = name
|
16
|
-
@recorder = recorder
|
17
|
-
end
|
18
|
-
|
19
|
-
def call(*args)
|
20
|
-
@recorder << [@name, 'before']
|
21
|
-
yield
|
22
|
-
@recorder << [@name, 'after']
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'supports custom middleware' do
|
27
|
-
chain = Sidekiq::Middleware::Chain.new
|
28
|
-
chain.add CustomMiddleware, 1, []
|
29
|
-
|
30
|
-
assert_equal CustomMiddleware, chain.entries.last.klass
|
31
|
-
end
|
32
|
-
|
33
|
-
class CustomWorker
|
34
|
-
$recorder = []
|
35
|
-
include Sidekiq::Worker
|
36
|
-
def perform(recorder)
|
37
|
-
$recorder << ['work_performed']
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class NonYieldingMiddleware
|
42
|
-
def call(*args)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class AnotherCustomMiddleware
|
47
|
-
def initialize(name, recorder)
|
48
|
-
@name = name
|
49
|
-
@recorder = recorder
|
50
|
-
end
|
51
|
-
|
52
|
-
def call(*args)
|
53
|
-
@recorder << [@name, 'before']
|
54
|
-
yield
|
55
|
-
@recorder << [@name, 'after']
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
class YetAnotherCustomMiddleware
|
60
|
-
def initialize(name, recorder)
|
61
|
-
@name = name
|
62
|
-
@recorder = recorder
|
63
|
-
end
|
64
|
-
|
65
|
-
def call(*args)
|
66
|
-
@recorder << [@name, 'before']
|
67
|
-
yield
|
68
|
-
@recorder << [@name, 'after']
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'executes middleware in the proper order' do
|
73
|
-
msg = Sidekiq.dump_json({ 'class' => CustomWorker.to_s, 'args' => [$recorder] })
|
74
|
-
|
75
|
-
Sidekiq.server_middleware do |chain|
|
76
|
-
# should only add once, second should replace the first
|
77
|
-
2.times { |i| chain.add CustomMiddleware, i.to_s, $recorder }
|
78
|
-
chain.insert_before CustomMiddleware, AnotherCustomMiddleware, '2', $recorder
|
79
|
-
chain.insert_after AnotherCustomMiddleware, YetAnotherCustomMiddleware, '3', $recorder
|
80
|
-
end
|
81
|
-
|
82
|
-
boss = Minitest::Mock.new
|
83
|
-
boss.expect(:options, {:queues => ['default'] }, [])
|
84
|
-
boss.expect(:options, {:queues => ['default'] }, [])
|
85
|
-
processor = Sidekiq::Processor.new(boss)
|
86
|
-
boss.expect(:processor_done, nil, [processor])
|
87
|
-
processor.process(Sidekiq::BasicFetch::UnitOfWork.new('queue:default', msg))
|
88
|
-
assert_equal %w(2 before 3 before 1 before work_performed 1 after 3 after 2 after), $recorder.flatten
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'correctly replaces middleware when using middleware with options in the initializer' do
|
92
|
-
chain = Sidekiq::Middleware::Chain.new
|
93
|
-
chain.add Sidekiq::Middleware::Server::RetryJobs
|
94
|
-
chain.add Sidekiq::Middleware::Server::RetryJobs, {:max_retries => 5}
|
95
|
-
assert_equal 1, chain.count
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'correctly prepends middleware' do
|
99
|
-
chain = Sidekiq::Middleware::Chain.new
|
100
|
-
chain_entries = chain.entries
|
101
|
-
chain.add CustomMiddleware
|
102
|
-
chain.prepend YetAnotherCustomMiddleware
|
103
|
-
assert_equal YetAnotherCustomMiddleware, chain_entries.first.klass
|
104
|
-
assert_equal CustomMiddleware, chain_entries.last.klass
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'allows middleware to abruptly stop processing rest of chain' do
|
108
|
-
recorder = []
|
109
|
-
chain = Sidekiq::Middleware::Chain.new
|
110
|
-
chain.add NonYieldingMiddleware
|
111
|
-
chain.add CustomMiddleware, 1, recorder
|
112
|
-
|
113
|
-
final_action = nil
|
114
|
-
chain.invoke { final_action = true }
|
115
|
-
assert_equal nil, final_action
|
116
|
-
assert_equal [], recorder
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
describe 'i18n' do
|
121
|
-
before do
|
122
|
-
require 'i18n'
|
123
|
-
I18n.enforce_available_locales = false
|
124
|
-
require 'sidekiq/middleware/i18n'
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'saves and restores locale' do
|
128
|
-
I18n.locale = 'fr'
|
129
|
-
msg = {}
|
130
|
-
mw = Sidekiq::Middleware::I18n::Client.new
|
131
|
-
mw.call(nil, msg, nil, nil) { }
|
132
|
-
assert_equal :fr, msg['locale']
|
133
|
-
|
134
|
-
msg['locale'] = 'jp'
|
135
|
-
I18n.locale = I18n.default_locale
|
136
|
-
assert_equal :en, I18n.locale
|
137
|
-
mw = Sidekiq::Middleware::I18n::Server.new
|
138
|
-
mw.call(nil, msg, nil) do
|
139
|
-
assert_equal :jp, I18n.locale
|
140
|
-
end
|
141
|
-
assert_equal :en, I18n.locale
|
142
|
-
end
|
143
|
-
|
144
|
-
it 'supports I18n.enforce_available_locales = true' do
|
145
|
-
I18n.enforce_available_locales = true
|
146
|
-
I18n.available_locales = [:en, :jp]
|
147
|
-
|
148
|
-
msg = { 'locale' => 'jp' }
|
149
|
-
mw = Sidekiq::Middleware::I18n::Server.new
|
150
|
-
mw.call(nil, msg, nil) do
|
151
|
-
assert_equal :jp, I18n.locale
|
152
|
-
end
|
153
|
-
|
154
|
-
I18n.enforce_available_locales = false
|
155
|
-
I18n.available_locales = nil
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|