shoryuken 2.1.1 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +5 -8
- data/.rubocop.yml +8 -2
- data/.travis.yml +6 -0
- data/CHANGELOG.md +167 -0
- data/Gemfile +2 -0
- data/README.md +16 -155
- data/Rakefile +0 -1
- data/bin/cli/base.rb +40 -0
- data/bin/cli/sqs.rb +204 -0
- data/bin/shoryuken +55 -9
- data/examples/default_worker.rb +1 -1
- data/lib/shoryuken/client.rb +3 -15
- data/lib/shoryuken/default_worker_registry.rb +10 -6
- data/lib/shoryuken/environment_loader.rb +60 -57
- data/lib/shoryuken/fetcher.rb +21 -51
- data/lib/shoryuken/launcher.rb +77 -23
- data/lib/shoryuken/logging.rb +0 -5
- data/lib/shoryuken/manager.rb +54 -205
- data/lib/shoryuken/message.rb +4 -13
- data/lib/shoryuken/middleware/chain.rb +1 -18
- data/lib/shoryuken/middleware/server/auto_delete.rb +3 -8
- data/lib/shoryuken/middleware/server/auto_extend_visibility.rb +16 -17
- data/lib/shoryuken/middleware/server/exponential_backoff_retry.rb +37 -22
- data/lib/shoryuken/middleware/server/timing.rb +2 -2
- data/lib/shoryuken/options.rb +196 -0
- data/lib/shoryuken/polling/base.rb +67 -0
- data/lib/shoryuken/polling/strict_priority.rb +77 -0
- data/lib/shoryuken/polling/weighted_round_robin.rb +66 -0
- data/lib/shoryuken/processor.rb +27 -25
- data/lib/shoryuken/queue.rb +28 -9
- data/lib/shoryuken/runner.rb +131 -0
- data/lib/shoryuken/util.rb +1 -9
- data/lib/shoryuken/version.rb +1 -1
- data/lib/shoryuken/worker.rb +9 -1
- data/lib/shoryuken.rb +47 -157
- data/shoryuken.gemspec +7 -7
- data/spec/integration/launcher_spec.rb +15 -8
- data/spec/shoryuken/client_spec.rb +2 -45
- data/spec/shoryuken/default_worker_registry_spec.rb +12 -10
- data/spec/shoryuken/environment_loader_spec.rb +54 -0
- data/spec/shoryuken/fetcher_spec.rb +27 -46
- data/spec/shoryuken/manager_spec.rb +80 -93
- data/spec/shoryuken/middleware/chain_spec.rb +0 -24
- data/spec/shoryuken/middleware/server/auto_delete_spec.rb +2 -2
- data/spec/shoryuken/middleware/server/auto_extend_visibility_spec.rb +7 -3
- data/spec/shoryuken/middleware/server/exponential_backoff_retry_spec.rb +56 -33
- data/spec/shoryuken/middleware/server/timing_spec.rb +5 -3
- data/spec/shoryuken/options_spec.rb +100 -0
- data/spec/shoryuken/polling/strict_priority_spec.rb +140 -0
- data/spec/shoryuken/polling/weighted_round_robin_spec.rb +99 -0
- data/spec/shoryuken/processor_spec.rb +20 -37
- data/spec/shoryuken/queue_spec.rb +72 -26
- data/spec/shoryuken/{cli_spec.rb → runner_spec.rb} +11 -26
- data/spec/shoryuken_spec.rb +1 -48
- data/spec/spec_helper.rb +14 -20
- data/test_workers/endless_interruptive_worker.rb +41 -0
- data/test_workers/endless_uninterruptive_worker.rb +44 -0
- metadata +39 -34
- data/lib/shoryuken/aws_config.rb +0 -64
- data/lib/shoryuken/cli.rb +0 -215
- data/lib/shoryuken/sns_arn.rb +0 -27
- data/lib/shoryuken/topic.rb +0 -17
- data/spec/shoryuken/sns_arn_spec.rb +0 -42
- data/spec/shoryuken/topic_spec.rb +0 -32
- data/spec/shoryuken_endpoint.yml +0 -6
data/lib/shoryuken/util.rb
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
1
|
module Shoryuken
|
|
2
2
|
module Util
|
|
3
|
-
def watchdog(last_words)
|
|
4
|
-
yield
|
|
5
|
-
rescue => ex
|
|
6
|
-
logger.error { last_words }
|
|
7
|
-
logger.error { ex }
|
|
8
|
-
logger.error { ex.backtrace.join("\n") }
|
|
9
|
-
end
|
|
10
|
-
|
|
11
3
|
def logger
|
|
12
4
|
Shoryuken.logger
|
|
13
5
|
end
|
|
@@ -38,7 +30,7 @@ module Shoryuken
|
|
|
38
30
|
end
|
|
39
31
|
|
|
40
32
|
def worker_name(worker_class, sqs_msg, body = nil)
|
|
41
|
-
if
|
|
33
|
+
if Shoryuken.active_job? \
|
|
42
34
|
&& !sqs_msg.is_a?(Array) \
|
|
43
35
|
&& sqs_msg.message_attributes \
|
|
44
36
|
&& sqs_msg.message_attributes['shoryuken_class'] \
|
data/lib/shoryuken/version.rb
CHANGED
data/lib/shoryuken/worker.rb
CHANGED
|
@@ -48,6 +48,14 @@ module Shoryuken
|
|
|
48
48
|
!!get_shoryuken_options['auto_visibility_timeout']
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
def exponential_backoff?
|
|
52
|
+
!!get_shoryuken_options['retry_intervals']
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def auto_delete?
|
|
56
|
+
!!(get_shoryuken_options['delete'] || get_shoryuken_options['auto_delete'])
|
|
57
|
+
end
|
|
58
|
+
|
|
51
59
|
def get_shoryuken_options # :nodoc:
|
|
52
60
|
@shoryuken_options || Shoryuken.default_worker_options
|
|
53
61
|
end
|
|
@@ -63,7 +71,7 @@ module Shoryuken
|
|
|
63
71
|
|
|
64
72
|
def normalize_worker_queue!
|
|
65
73
|
queue = @shoryuken_options['queue']
|
|
66
|
-
if queue.respond_to?
|
|
74
|
+
if queue.respond_to?(:call)
|
|
67
75
|
queue = queue.call
|
|
68
76
|
@shoryuken_options['queue'] = queue
|
|
69
77
|
end
|
data/lib/shoryuken.rb
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
require 'yaml'
|
|
2
|
+
require 'json'
|
|
2
3
|
require 'aws-sdk-core'
|
|
3
4
|
require 'time'
|
|
5
|
+
require 'concurrent'
|
|
4
6
|
|
|
5
7
|
require 'shoryuken/version'
|
|
6
8
|
require 'shoryuken/core_ext'
|
|
7
9
|
require 'shoryuken/util'
|
|
8
10
|
require 'shoryuken/logging'
|
|
9
|
-
require 'shoryuken/aws_config'
|
|
10
11
|
require 'shoryuken/environment_loader'
|
|
11
12
|
require 'shoryuken/queue'
|
|
12
13
|
require 'shoryuken/message'
|
|
@@ -19,163 +20,52 @@ require 'shoryuken/middleware/server/auto_delete'
|
|
|
19
20
|
Shoryuken::Middleware::Server.autoload :AutoExtendVisibility, 'shoryuken/middleware/server/auto_extend_visibility'
|
|
20
21
|
require 'shoryuken/middleware/server/exponential_backoff_retry'
|
|
21
22
|
require 'shoryuken/middleware/server/timing'
|
|
22
|
-
require 'shoryuken/
|
|
23
|
-
require 'shoryuken/
|
|
23
|
+
require 'shoryuken/polling/base'
|
|
24
|
+
require 'shoryuken/polling/weighted_round_robin'
|
|
25
|
+
require 'shoryuken/polling/strict_priority'
|
|
26
|
+
require 'shoryuken/manager'
|
|
27
|
+
require 'shoryuken/launcher'
|
|
28
|
+
require 'shoryuken/processor'
|
|
29
|
+
require 'shoryuken/fetcher'
|
|
30
|
+
require 'shoryuken/options'
|
|
24
31
|
|
|
25
32
|
module Shoryuken
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def worker_registry
|
|
65
|
-
@@worker_registry
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def active_job_queue_name_prefixing
|
|
69
|
-
@@active_job_queue_name_prefixing
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def active_job_queue_name_prefixing=(prefixing)
|
|
73
|
-
@@active_job_queue_name_prefixing = prefixing
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
##
|
|
77
|
-
# Configuration for Shoryuken server, use like:
|
|
78
|
-
#
|
|
79
|
-
# Shoryuken.configure_server do |config|
|
|
80
|
-
# config.aws = { :sqs_endpoint => '...', :access_key_id: '...', :secret_access_key: '...', region: '...' }
|
|
81
|
-
# end
|
|
82
|
-
def configure_server
|
|
83
|
-
yield self if server?
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def server_middleware
|
|
87
|
-
@server_chain ||= default_server_middleware
|
|
88
|
-
yield @server_chain if block_given?
|
|
89
|
-
@server_chain
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
##
|
|
93
|
-
# Configuration for Shoryuken client, use like:
|
|
94
|
-
#
|
|
95
|
-
# Shoryuken.configure_client do |config|
|
|
96
|
-
# config.aws = { :sqs_endpoint => '...', :access_key_id: '...', :secret_access_key: '...', region: '...' }
|
|
97
|
-
# end
|
|
98
|
-
def configure_client
|
|
99
|
-
yield self unless server?
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def client_middleware
|
|
103
|
-
@client_chain ||= default_client_middleware
|
|
104
|
-
yield @client_chain if block_given?
|
|
105
|
-
@client_chain
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
def default_worker_options
|
|
109
|
-
@@default_worker_options ||= {
|
|
110
|
-
'queue' => 'default',
|
|
111
|
-
'delete' => false,
|
|
112
|
-
'auto_delete' => false,
|
|
113
|
-
'auto_visibility_timeout' => false,
|
|
114
|
-
'retry_intervals' => nil,
|
|
115
|
-
'batch' => false }
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def default_worker_options=(options)
|
|
119
|
-
@@default_worker_options = options
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def on_aws_initialization(&block)
|
|
123
|
-
@aws_initialization_callback = block
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
def on_start(&block)
|
|
127
|
-
@start_callback = block
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def on_stop(&block)
|
|
131
|
-
@stop_callback = block
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
def aws=(hash)
|
|
135
|
-
Shoryuken::AwsConfig.setup(hash)
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
# Register a block to run at a point in the Shoryuken lifecycle.
|
|
139
|
-
# :startup, :quiet or :shutdown are valid events.
|
|
140
|
-
#
|
|
141
|
-
# Shoryuken.configure_server do |config|
|
|
142
|
-
# config.on(:shutdown) do
|
|
143
|
-
# puts "Goodbye cruel world!"
|
|
144
|
-
# end
|
|
145
|
-
# end
|
|
146
|
-
def on(event, &block)
|
|
147
|
-
fail ArgumentError, "Symbols only please: #{event}" unless event.is_a?(Symbol)
|
|
148
|
-
fail ArgumentError, "Invalid event name: #{event}" unless options[:lifecycle_events].key?(event)
|
|
149
|
-
options[:lifecycle_events][event] << block
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
attr_reader :aws_initialization_callback,
|
|
153
|
-
:start_callback,
|
|
154
|
-
:stop_callback
|
|
155
|
-
|
|
156
|
-
private
|
|
157
|
-
|
|
158
|
-
def default_server_middleware
|
|
159
|
-
Middleware::Chain.new do |m|
|
|
160
|
-
m.add Middleware::Server::Timing
|
|
161
|
-
m.add Middleware::Server::ExponentialBackoffRetry
|
|
162
|
-
m.add Middleware::Server::AutoDelete
|
|
163
|
-
m.add Middleware::Server::AutoExtendVisibility
|
|
164
|
-
if defined?(::ActiveRecord::Base)
|
|
165
|
-
require 'shoryuken/middleware/server/active_record'
|
|
166
|
-
m.add Middleware::Server::ActiveRecord
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
def default_client_middleware
|
|
172
|
-
Middleware::Chain.new
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
def server?
|
|
176
|
-
defined?(Shoryuken::CLI)
|
|
177
|
-
end
|
|
178
|
-
end
|
|
33
|
+
extend SingleForwardable
|
|
34
|
+
|
|
35
|
+
def_delegators(
|
|
36
|
+
:'Shoryuken::Options',
|
|
37
|
+
:active_job?,
|
|
38
|
+
:add_group,
|
|
39
|
+
:groups,
|
|
40
|
+
:add_queue,
|
|
41
|
+
:ungrouped_queues,
|
|
42
|
+
:worker_registry,
|
|
43
|
+
:worker_registry=,
|
|
44
|
+
:polling_strategy,
|
|
45
|
+
:start_callback,
|
|
46
|
+
:start_callback=,
|
|
47
|
+
:stop_callback,
|
|
48
|
+
:stop_callback=,
|
|
49
|
+
:active_job_queue_name_prefixing,
|
|
50
|
+
:active_job_queue_name_prefixing=,
|
|
51
|
+
:sqs_client,
|
|
52
|
+
:sqs_client=,
|
|
53
|
+
:sqs_client_receive_message_opts,
|
|
54
|
+
:sqs_client_receive_message_opts=,
|
|
55
|
+
:options,
|
|
56
|
+
:logger,
|
|
57
|
+
:register_worker,
|
|
58
|
+
:configure_server,
|
|
59
|
+
:server?,
|
|
60
|
+
:server_middleware,
|
|
61
|
+
:configure_client,
|
|
62
|
+
:client_middleware,
|
|
63
|
+
:default_worker_options,
|
|
64
|
+
:default_worker_options=,
|
|
65
|
+
:on_start,
|
|
66
|
+
:on_stop,
|
|
67
|
+
:on
|
|
68
|
+
)
|
|
179
69
|
end
|
|
180
70
|
|
|
181
|
-
require 'shoryuken/extensions/active_job_adapter' if
|
|
71
|
+
require 'shoryuken/extensions/active_job_adapter' if Shoryuken.active_job?
|
data/shoryuken.gemspec
CHANGED
|
@@ -6,14 +6,14 @@ require 'shoryuken/version'
|
|
|
6
6
|
Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = 'shoryuken'
|
|
8
8
|
spec.version = Shoryuken::VERSION
|
|
9
|
-
spec.authors = ['Pablo Cantero'
|
|
10
|
-
spec.email = ['pablo@pablocantero.com'
|
|
11
|
-
spec.description = spec.summary =
|
|
9
|
+
spec.authors = ['Pablo Cantero']
|
|
10
|
+
spec.email = ['pablo@pablocantero.com']
|
|
11
|
+
spec.description = spec.summary = 'Shoryuken is a super efficient AWS SQS thread based message processor'
|
|
12
12
|
spec.homepage = 'https://github.com/phstc/shoryuken'
|
|
13
13
|
spec.license = 'LGPL-3.0'
|
|
14
14
|
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0")
|
|
16
|
-
spec.executables = %w
|
|
16
|
+
spec.executables = %w(shoryuken)
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
18
18
|
spec.require_paths = ['lib']
|
|
19
19
|
|
|
@@ -21,9 +21,9 @@ Gem::Specification.new do |spec|
|
|
|
21
21
|
spec.add_development_dependency 'rake'
|
|
22
22
|
spec.add_development_dependency 'rspec'
|
|
23
23
|
spec.add_development_dependency 'pry-byebug'
|
|
24
|
-
spec.add_development_dependency 'nokogiri'
|
|
25
24
|
spec.add_development_dependency 'dotenv'
|
|
26
25
|
|
|
27
|
-
spec.add_dependency 'aws-sdk-core', '
|
|
28
|
-
spec.add_dependency '
|
|
26
|
+
spec.add_dependency 'aws-sdk-core', '> 2'
|
|
27
|
+
spec.add_dependency 'concurrent-ruby'
|
|
28
|
+
spec.add_dependency 'thor'
|
|
29
29
|
end
|
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
require 'shoryuken/manager'
|
|
3
3
|
require 'shoryuken/launcher'
|
|
4
|
+
require 'securerandom'
|
|
4
5
|
|
|
5
6
|
RSpec.describe Shoryuken::Launcher do
|
|
6
7
|
describe 'Consuming messages', slow: :true do
|
|
7
8
|
before do
|
|
8
|
-
|
|
9
|
+
Aws.config[:stub_responses] = false
|
|
10
|
+
Aws.config[:region] = 'us-east-1'
|
|
9
11
|
|
|
10
12
|
StandardWorker.received_messages = 0
|
|
11
13
|
|
|
12
|
-
queue = "
|
|
14
|
+
queue = "shoryuken-travis-#{StandardWorker}-#{SecureRandom.uuid}"
|
|
13
15
|
|
|
14
|
-
Shoryuken::Client.sqs.create_queue
|
|
16
|
+
Shoryuken::Client.sqs.create_queue(queue_name: queue)
|
|
15
17
|
|
|
16
|
-
Shoryuken.
|
|
18
|
+
Shoryuken.add_group('default', 1)
|
|
19
|
+
Shoryuken.add_queue(queue, 1, 'default')
|
|
17
20
|
|
|
18
21
|
StandardWorker.get_shoryuken_options['queue'] = queue
|
|
19
22
|
|
|
20
|
-
Shoryuken.register_worker
|
|
23
|
+
Shoryuken.register_worker(queue, StandardWorker)
|
|
21
24
|
end
|
|
22
25
|
|
|
23
26
|
after do
|
|
24
|
-
|
|
27
|
+
Aws.config[:stub_responses] = true
|
|
25
28
|
|
|
26
|
-
Shoryuken::Client.sqs.
|
|
29
|
+
queue_url = Shoryuken::Client.sqs.get_queue_url(
|
|
30
|
+
queue_name: StandardWorker.get_shoryuken_options['queue']
|
|
31
|
+
).queue_url
|
|
32
|
+
|
|
33
|
+
Shoryuken::Client.sqs.delete_queue(queue_url: queue_url)
|
|
27
34
|
end
|
|
28
35
|
|
|
29
36
|
it 'consumes as a command worker' do
|
|
@@ -60,7 +67,7 @@ RSpec.describe Shoryuken::Launcher do
|
|
|
60
67
|
end
|
|
61
68
|
|
|
62
69
|
def poll_queues_until
|
|
63
|
-
subject.
|
|
70
|
+
subject.start
|
|
64
71
|
|
|
65
72
|
Timeout::timeout(10) do
|
|
66
73
|
begin
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Shoryuken::Client do
|
|
3
|
+
RSpec.describe Shoryuken::Client do
|
|
4
4
|
let(:credentials) { Aws::Credentials.new('access_key_id', 'secret_access_key') }
|
|
5
5
|
let(:sqs) { Aws::SQS::Client.new(stub_responses: true, credentials: credentials) }
|
|
6
6
|
let(:queue_name) { 'shoryuken' }
|
|
7
7
|
let(:queue_url) { 'https://eu-west-1.amazonaws.com:6059/123456789012/shoryuken' }
|
|
8
|
-
let(:sqs_endpoint) { 'http://localhost:4568' }
|
|
9
|
-
let(:sns_endpoint) { 'http://0.0.0.0:4568' }
|
|
10
8
|
|
|
11
9
|
describe '.queue' do
|
|
12
10
|
before do
|
|
13
11
|
described_class.sqs = sqs
|
|
14
12
|
end
|
|
13
|
+
|
|
15
14
|
it 'memoizes queues' do
|
|
16
15
|
sqs.stub_responses(:get_queue_url, { queue_url: queue_url }, { queue_url: 'xyz' })
|
|
17
16
|
|
|
@@ -19,46 +18,4 @@ describe Shoryuken::Client do
|
|
|
19
18
|
expect(Shoryuken::Client.queues(queue_name).url).to eq queue_url
|
|
20
19
|
end
|
|
21
20
|
end
|
|
22
|
-
|
|
23
|
-
describe 'environment variable endpoints' do
|
|
24
|
-
before do
|
|
25
|
-
ENV['AWS_SQS_ENDPOINT'] = sqs_endpoint
|
|
26
|
-
ENV['AWS_SNS_ENDPOINT'] = sns_endpoint
|
|
27
|
-
ENV['AWS_REGION'] = 'us-east-1'
|
|
28
|
-
Shoryuken.options[:aws] = {}
|
|
29
|
-
Shoryuken::AwsConfig.options = {}
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it 'will use config file settings if set' do
|
|
33
|
-
load_config_file_by_file_name('shoryuken_endpoint.yml')
|
|
34
|
-
expect(described_class.sqs.config.endpoint.to_s).to eql('https://github.com/phstc/shoryuken:4568')
|
|
35
|
-
expect(described_class.sns.config.endpoint.to_s).to eq('http://127.0.0.1:4568')
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'should fallback to environment variable if config file not found or set' do
|
|
39
|
-
load_config_file_by_file_name(nil)
|
|
40
|
-
expect(described_class.sqs.config.endpoint.to_s).to eql(sqs_endpoint)
|
|
41
|
-
expect(described_class.sns.config.endpoint.to_s).to eq(sns_endpoint)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'should fallback to environment variable if config file found but settings not set' do
|
|
45
|
-
load_config_file_by_file_name('shoryuken.yml')
|
|
46
|
-
expect(described_class.sqs.config.endpoint.to_s).to eql(sqs_endpoint)
|
|
47
|
-
expect(described_class.sns.config.endpoint.to_s).to eq(sns_endpoint)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it 'will fallback to default settings if no config file settings or environment variables found' do
|
|
51
|
-
ENV['AWS_SQS_ENDPOINT'] = nil
|
|
52
|
-
ENV['AWS_SNS_ENDPOINT'] = nil
|
|
53
|
-
load_config_file_by_file_name('shoryuken.yml')
|
|
54
|
-
expect(described_class.sqs.config.endpoint.to_s).to eql('https://sqs.us-east-1.amazonaws.com')
|
|
55
|
-
expect(described_class.sns.config.endpoint.to_s).to eq('https://sns.us-east-1.amazonaws.com')
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
def load_config_file_by_file_name(file_name)
|
|
60
|
-
path_name = file_name ? File.join(File.expand_path('../../..', __FILE__), 'spec', file_name) : nil
|
|
61
|
-
loader = Shoryuken::EnvironmentLoader.setup_options(config_file: path_name)
|
|
62
|
-
loader.load
|
|
63
|
-
end
|
|
64
21
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# rubocop:disable Metrics/BlockLength
|
|
4
|
+
RSpec.describe Shoryuken::DefaultWorkerRegistry do
|
|
4
5
|
class RegistryTestWorker
|
|
5
6
|
include Shoryuken::Worker
|
|
6
7
|
|
|
@@ -42,16 +43,17 @@ describe Shoryuken::DefaultWorkerRegistry do
|
|
|
42
43
|
end
|
|
43
44
|
|
|
44
45
|
describe 'a registry with workers is handling messages' do
|
|
45
|
-
def build_message
|
|
46
|
+
def build_message(queue, explicit_worker = nil)
|
|
46
47
|
attributes = {}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
data_type: 'String' }
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
|
|
49
|
+
if explicit_worker
|
|
50
|
+
attributes['shoryuken_class'] = { string_value: explicit_worker.to_s, data_type: 'String' }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
double(Shoryuken::Message,
|
|
54
|
+
body: 'test',
|
|
55
|
+
message_attributes: attributes,
|
|
56
|
+
message_id: SecureRandom.uuid)
|
|
55
57
|
end
|
|
56
58
|
|
|
57
59
|
context 'a batch of messages is being processed' do
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'active_job'
|
|
3
|
+
|
|
4
|
+
RSpec.describe Shoryuken::EnvironmentLoader do
|
|
5
|
+
subject { described_class.new({}) }
|
|
6
|
+
|
|
7
|
+
describe '#parse_queues' do
|
|
8
|
+
before do
|
|
9
|
+
allow(subject).to receive(:load_rails)
|
|
10
|
+
allow(subject).to receive(:prefix_active_job_queue_names)
|
|
11
|
+
allow(subject).to receive(:require_workers)
|
|
12
|
+
allow(subject).to receive(:validate_queues)
|
|
13
|
+
allow(subject).to receive(:validate_workers)
|
|
14
|
+
allow(subject).to receive(:patch_deprecated_workers)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
specify do
|
|
18
|
+
Shoryuken.options[:queues] = ['queue1', ['queue2', 2]]
|
|
19
|
+
subject.load
|
|
20
|
+
|
|
21
|
+
expect(Shoryuken.groups['default'][:queues]).to eq(%w(queue1 queue2 queue2))
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe '#prefix_active_job_queue_names' do
|
|
26
|
+
before do
|
|
27
|
+
allow(subject).to receive(:load_rails)
|
|
28
|
+
allow(subject).to receive(:require_workers)
|
|
29
|
+
allow(subject).to receive(:validate_queues)
|
|
30
|
+
allow(subject).to receive(:validate_workers)
|
|
31
|
+
allow(subject).to receive(:patch_deprecated_workers)
|
|
32
|
+
|
|
33
|
+
ActiveJob::Base.queue_name_prefix = 'test'
|
|
34
|
+
ActiveJob::Base.queue_name_delimiter = '_'
|
|
35
|
+
|
|
36
|
+
allow(Shoryuken).to receive(:active_job?).and_return(true)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
specify do
|
|
40
|
+
Shoryuken.active_job_queue_name_prefixing = true
|
|
41
|
+
|
|
42
|
+
Shoryuken.options[:queues] = ['queue1', ['queue2', 2]]
|
|
43
|
+
|
|
44
|
+
Shoryuken.options[:groups] = {
|
|
45
|
+
'group1' => { queues: %w(group1_queue1 group1_queue2) }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
subject.load
|
|
49
|
+
|
|
50
|
+
expect(Shoryuken.groups['default'][:queues]).to eq(%w(test_queue1 test_queue2 test_queue2))
|
|
51
|
+
expect(Shoryuken.groups['group1'][:queues]).to eq(%w(test_group1_queue1 test_group1_queue2))
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
@@ -2,69 +2,50 @@ require 'spec_helper'
|
|
|
2
2
|
require 'shoryuken/manager'
|
|
3
3
|
require 'shoryuken/fetcher'
|
|
4
4
|
|
|
5
|
-
describe Shoryuken::Fetcher do
|
|
6
|
-
let(:
|
|
7
|
-
let(:
|
|
8
|
-
let(:
|
|
5
|
+
RSpec.describe Shoryuken::Fetcher do
|
|
6
|
+
let(:queue) { instance_double('Shoryuken::Queue') }
|
|
7
|
+
let(:queue_name) { 'default' }
|
|
8
|
+
let(:queue_config) { Shoryuken::Polling::QueueConfiguration.new(queue_name, {}) }
|
|
9
|
+
let(:group) { 'default' }
|
|
9
10
|
|
|
10
11
|
let(:sqs_msg) do
|
|
11
|
-
double
|
|
12
|
+
double(
|
|
13
|
+
Shoryuken::Message,
|
|
12
14
|
queue_url: queue_name,
|
|
13
15
|
body: 'test',
|
|
14
|
-
message_id: '
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
subject { described_class.new(manager) }
|
|
18
|
-
|
|
19
|
-
before do
|
|
20
|
-
allow(manager).to receive(:async).and_return(manager)
|
|
21
|
-
allow(Shoryuken::Client).to receive(:queues).with(queue_name).and_return(queue)
|
|
16
|
+
message_id: 'fc754df79cc24c4196ca5996a44b771e',
|
|
17
|
+
)
|
|
22
18
|
end
|
|
23
19
|
|
|
20
|
+
subject { described_class.new(group) }
|
|
24
21
|
|
|
25
22
|
describe '#fetch' do
|
|
26
|
-
|
|
27
|
-
allow(queue).to receive(:receive_messages).with(max_number_of_messages: 1, attribute_names: ['All'], message_attribute_names: ['All']).and_return([])
|
|
28
|
-
|
|
29
|
-
expect(manager).to receive(:pause_queue!).with(queue_name)
|
|
30
|
-
expect(manager).to receive(:dispatch)
|
|
31
|
-
|
|
32
|
-
subject.fetch(queue_name, 1)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
it 'assigns messages' do
|
|
36
|
-
allow(queue).to receive(:receive_messages).with(max_number_of_messages: 5, attribute_names: ['All'], message_attribute_names: ['All']).and_return(sqs_msg)
|
|
37
|
-
|
|
38
|
-
expect(manager).to receive(:rebalance_queue_weight!).with(queue_name)
|
|
39
|
-
expect(manager).to receive(:assign).with(queue_name, sqs_msg)
|
|
40
|
-
expect(manager).to receive(:dispatch)
|
|
41
|
-
|
|
42
|
-
subject.fetch(queue_name, 5)
|
|
43
|
-
end
|
|
23
|
+
let(:limit) { 1 }
|
|
44
24
|
|
|
45
|
-
|
|
46
|
-
|
|
25
|
+
specify do
|
|
26
|
+
expect(Shoryuken::Client).to receive(:queues).with(queue_name).and_return(queue)
|
|
47
27
|
|
|
48
|
-
|
|
28
|
+
Shoryuken.sqs_client_receive_message_opts[group] = { wait_time_seconds: 10 }
|
|
49
29
|
|
|
50
|
-
expect(
|
|
51
|
-
|
|
52
|
-
|
|
30
|
+
expect(queue).to receive(:receive_messages).
|
|
31
|
+
with(wait_time_seconds: 10, max_number_of_messages: limit, message_attribute_names: ['All'], attribute_names: ['All']).
|
|
32
|
+
and_return([])
|
|
53
33
|
|
|
54
|
-
subject.fetch(
|
|
34
|
+
subject.fetch(queue_config, limit)
|
|
55
35
|
end
|
|
56
36
|
|
|
57
|
-
context 'when
|
|
58
|
-
let(:
|
|
37
|
+
context 'when limit is greater than FETCH_LIMIT' do
|
|
38
|
+
let(:limit) { 20 }
|
|
59
39
|
|
|
60
|
-
|
|
61
|
-
|
|
40
|
+
specify do
|
|
41
|
+
Shoryuken.sqs_client_receive_message_opts[group] = {}
|
|
62
42
|
|
|
63
|
-
|
|
64
|
-
expect(
|
|
65
|
-
|
|
43
|
+
allow(Shoryuken::Client).to receive(:queues).with(queue_name).and_return(queue)
|
|
44
|
+
expect(queue).to receive(:receive_messages).
|
|
45
|
+
with(max_number_of_messages: described_class::FETCH_LIMIT, attribute_names: ['All'], message_attribute_names: ['All']).
|
|
46
|
+
and_return([])
|
|
66
47
|
|
|
67
|
-
subject.fetch(
|
|
48
|
+
subject.fetch(queue_config, limit)
|
|
68
49
|
end
|
|
69
50
|
end
|
|
70
51
|
end
|