shoryuken 3.1.4 → 3.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/shoryuken/launcher.rb +2 -17
- data/lib/shoryuken/manager.rb +12 -3
- data/lib/shoryuken/queue.rb +12 -5
- data/lib/shoryuken/version.rb +1 -1
- data/spec/shoryuken/queue_spec.rb +43 -32
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed935b3a706f2e96acd020a62bee5141910bf63f
|
4
|
+
data.tar.gz: 502827e59b4c18b605eccbd7c9b31829afaef23e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz: '
|
6
|
+
metadata.gz: 802af1fc13ac74c36745582d3b796def81bfdd53d8340a44ea212813a8cb3598d40969821c8172eeba6dca2a10a8be8affce9d7390dee028660a46f909533601
|
7
|
+
data.tar.gz: '075822afd74835bbe91e49efa991dc24957405ce830005f2f4c59d0add5e5db39633680a5bda5647af7ec7e74815ca0050ea6a316bf5e5bed870d7e048224db1'
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
## [v3.1.5] - 2017-07-23
|
2
|
+
|
3
|
+
- Fix memory leak
|
4
|
+
- [#414](https://github.com/phstc/shoryuken/pull/414)
|
5
|
+
|
6
|
+
- Fail fast on bad queue URLs
|
7
|
+
- [#413](https://github.com/phstc/shoryuken/pull/413)
|
8
|
+
|
1
9
|
## [v3.1.4] - 2017-07-14
|
2
10
|
|
3
11
|
- Require forwardable allowding to call `shoryuken` without `bundle exec`
|
data/lib/shoryuken/launcher.rb
CHANGED
@@ -3,8 +3,7 @@ module Shoryuken
|
|
3
3
|
include Util
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
@managers
|
7
|
-
@shutdowning = Concurrent::AtomicBoolean.new(false)
|
6
|
+
@managers = create_managers
|
8
7
|
end
|
9
8
|
|
10
9
|
def start
|
@@ -41,24 +40,10 @@ module Shoryuken
|
|
41
40
|
|
42
41
|
def start_managers
|
43
42
|
@managers.each do |manager|
|
44
|
-
Concurrent::
|
45
|
-
log_manager_failure(ex)
|
46
|
-
start_soft_shutdown
|
47
|
-
end
|
43
|
+
Concurrent::Future.execute { manager.start }
|
48
44
|
end
|
49
45
|
end
|
50
46
|
|
51
|
-
def start_soft_shutdown
|
52
|
-
Process.kill('USR1', Process.pid) if @shutdowning.make_true
|
53
|
-
end
|
54
|
-
|
55
|
-
def log_manager_failure(ex)
|
56
|
-
return unless ex
|
57
|
-
|
58
|
-
logger.error { "Manager failed: #{ex.message}" }
|
59
|
-
logger.error { ex.backtrace.join("\n") } unless ex.backtrace.nil?
|
60
|
-
end
|
61
|
-
|
62
47
|
def initiate_stop
|
63
48
|
logger.info { 'Shutting down' }
|
64
49
|
|
data/lib/shoryuken/manager.rb
CHANGED
@@ -27,9 +27,7 @@ module Shoryuken
|
|
27
27
|
def dispatch_loop
|
28
28
|
return unless running?
|
29
29
|
|
30
|
-
|
31
|
-
executor: @executor
|
32
|
-
) { dispatch }.then { dispatch_loop }.rescue { |ex| raise ex }
|
30
|
+
@executor.post { dispatch }
|
33
31
|
end
|
34
32
|
|
35
33
|
def dispatch
|
@@ -44,6 +42,10 @@ module Shoryuken
|
|
44
42
|
logger.debug { "Ready: #{ready}, Busy: #{busy}, Active Queues: #{@polling_strategy.active_queues}" }
|
45
43
|
|
46
44
|
batched_queue?(queue) ? dispatch_batch(queue) : dispatch_single_messages(queue)
|
45
|
+
|
46
|
+
dispatch_loop
|
47
|
+
rescue => ex
|
48
|
+
handle_dispatch_error(ex)
|
47
49
|
end
|
48
50
|
|
49
51
|
def busy
|
@@ -96,5 +98,12 @@ module Shoryuken
|
|
96
98
|
|
97
99
|
sqs_msgs
|
98
100
|
end
|
101
|
+
|
102
|
+
def handle_dispatch_error(ex)
|
103
|
+
logger.error { "Manager failed: #{ex.message}" }
|
104
|
+
logger.error { ex.backtrace.join("\n") } unless ex.backtrace.nil?
|
105
|
+
|
106
|
+
Process.kill('USR1', Process.pid)
|
107
|
+
end
|
99
108
|
end
|
100
109
|
end
|
data/lib/shoryuken/queue.rb
CHANGED
@@ -49,20 +49,27 @@ module Shoryuken
|
|
49
49
|
|
50
50
|
private
|
51
51
|
|
52
|
-
def
|
52
|
+
def set_by_name(name)
|
53
53
|
self.name = name
|
54
54
|
self.url = client.get_queue_url(queue_name: name).queue_url
|
55
|
-
rescue Aws::Errors::NoSuchEndpointError, Aws::SQS::Errors::NonExistentQueue => ex
|
56
|
-
raise ex, "The specified queue #{name} does not exist."
|
57
55
|
end
|
58
56
|
|
59
|
-
def
|
57
|
+
def set_by_url(url)
|
60
58
|
self.name = url.split('/').last
|
61
59
|
self.url = url
|
62
60
|
end
|
63
61
|
|
64
62
|
def set_name_and_url(name_or_url)
|
65
|
-
name_or_url.start_with?('https://sqs.')
|
63
|
+
if name_or_url.start_with?('https://sqs.')
|
64
|
+
set_by_url(name_or_url)
|
65
|
+
|
66
|
+
# anticipate the fifo? checker for validating the queue URL
|
67
|
+
return fifo?
|
68
|
+
end
|
69
|
+
|
70
|
+
set_by_name(name_or_url)
|
71
|
+
rescue Aws::Errors::NoSuchEndpointError, Aws::SQS::Errors::NonExistentQueue => ex
|
72
|
+
raise ex, "The specified queue #{name_or_url} does not exist."
|
66
73
|
end
|
67
74
|
|
68
75
|
def queue_attributes
|
data/lib/shoryuken/version.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
# rubocop:disable Metrics/BlockLength
|
3
4
|
RSpec.describe Shoryuken::Queue do
|
4
5
|
let(:credentials) { Aws::Credentials.new('access_key_id', 'secret_access_key') }
|
5
6
|
let(:sqs) { Aws::SQS::Client.new(stub_responses: true, credentials: credentials) }
|
@@ -15,10 +16,12 @@ RSpec.describe Shoryuken::Queue do
|
|
15
16
|
end
|
16
17
|
|
17
18
|
describe '#new' do
|
18
|
-
context 'when queue
|
19
|
-
|
19
|
+
context 'when queue URL supplied' do
|
20
|
+
it 'instantiates by URL and validate the URL' do
|
21
|
+
expect_any_instance_of(described_class).to receive(:fifo?).and_return(false)
|
22
|
+
|
23
|
+
subject = described_class.new(sqs, queue_url)
|
20
24
|
|
21
|
-
specify do
|
22
25
|
expect(subject.name).to eq(queue_name)
|
23
26
|
end
|
24
27
|
end
|
@@ -51,7 +54,9 @@ RSpec.describe Shoryuken::Queue do
|
|
51
54
|
failure = double(id: 'id', code: 'code', message: '...', sender_fault: false)
|
52
55
|
logger = double 'Logger'
|
53
56
|
|
54
|
-
expect(sqs).to
|
57
|
+
expect(sqs).to(
|
58
|
+
receive(:delete_message_batch).with(entries: entries, queue_url: queue_url).and_return(double(failed: [failure]))
|
59
|
+
)
|
55
60
|
expect(subject).to receive(:logger).and_return(logger)
|
56
61
|
expect(logger).to receive(:error)
|
57
62
|
|
@@ -111,36 +116,30 @@ RSpec.describe Shoryuken::Queue do
|
|
111
116
|
end
|
112
117
|
|
113
118
|
describe '#send_messages' do
|
114
|
-
before {
|
115
|
-
|
116
|
-
}
|
119
|
+
before { allow(subject).to receive(:fifo?).and_return(false) }
|
120
|
+
|
117
121
|
it 'accepts SQS request parameters' do
|
118
122
|
# https://docs.aws.amazon.com/sdkforruby/api/Aws/SQS/Client.html#send_message_batch-instance_method
|
119
|
-
expect(sqs).to
|
123
|
+
expect(sqs).to(
|
124
|
+
receive(:send_message_batch).with(hash_including(entries: [{id: '0', message_body: 'msg1'}, {id: '1', message_body: 'msg2'}]))
|
125
|
+
)
|
120
126
|
|
121
127
|
subject.send_messages(entries: [{id: '0', message_body: 'msg1'}, {id: '1', message_body: 'msg2'}])
|
122
128
|
end
|
123
129
|
|
124
130
|
it 'accepts an array of messages' do
|
125
|
-
options = { entries: [
|
126
|
-
message_body: 'msg1',
|
127
|
-
delay_seconds: 1,
|
128
|
-
|
129
|
-
{ id: '1',
|
130
|
-
message_body: 'msg2',
|
131
|
-
delay_seconds: 1,
|
132
|
-
message_attributes: { attr: 'attr2' } }] }
|
133
|
-
|
131
|
+
options = { entries: [
|
132
|
+
{ id: '0', message_body: 'msg1', delay_seconds: 1, message_attributes: { attr: 'attr1' } },
|
133
|
+
{ id: '1', message_body: 'msg2', delay_seconds: 1, message_attributes: { attr: 'attr2' } }
|
134
|
+
] }
|
134
135
|
expect(sqs).to receive(:send_message_batch).with(hash_including(options))
|
135
136
|
|
136
|
-
subject.send_messages(
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
message_attributes: { attr: 'attr2' }
|
143
|
-
}])
|
137
|
+
subject.send_messages(
|
138
|
+
[
|
139
|
+
{ message_body: 'msg1', delay_seconds: 1, message_attributes: { attr: 'attr1' } },
|
140
|
+
{ message_body: 'msg2', delay_seconds: 1, message_attributes: { attr: 'attr2' } }
|
141
|
+
]
|
142
|
+
)
|
144
143
|
end
|
145
144
|
|
146
145
|
context 'when FIFO' do
|
@@ -170,16 +169,24 @@ RSpec.describe Shoryuken::Queue do
|
|
170
169
|
expect(first_entry[:message_deduplication_id]).to eq 'my id'
|
171
170
|
end
|
172
171
|
|
173
|
-
subject.send_messages(
|
174
|
-
|
175
|
-
|
176
|
-
|
172
|
+
subject.send_messages(
|
173
|
+
[
|
174
|
+
{ message_body: 'msg1',
|
175
|
+
message_attributes: { attr: 'attr1' },
|
176
|
+
message_group_id: 'my group',
|
177
|
+
message_deduplication_id: 'my id' }
|
178
|
+
]
|
179
|
+
)
|
177
180
|
end
|
178
181
|
end
|
179
182
|
end
|
180
183
|
|
181
184
|
it 'accepts an array of string' do
|
182
|
-
expect(sqs).to
|
185
|
+
expect(sqs).to(
|
186
|
+
receive(:send_message_batch).with(
|
187
|
+
hash_including(entries: [{ id: '0', message_body: 'msg1' }, { id: '1', message_body: 'msg2' }])
|
188
|
+
)
|
189
|
+
)
|
183
190
|
|
184
191
|
subject.send_messages(%w(msg1 msg2))
|
185
192
|
end
|
@@ -189,9 +196,13 @@ RSpec.describe Shoryuken::Queue do
|
|
189
196
|
before do
|
190
197
|
attribute_response = double 'Aws::SQS::Types::GetQueueAttributesResponse'
|
191
198
|
|
192
|
-
allow(attribute_response).to
|
199
|
+
allow(attribute_response).to(
|
200
|
+
receive(:attributes).and_return('FifoQueue' => fifo.to_s, 'ContentBasedDeduplication' => 'true')
|
201
|
+
)
|
193
202
|
allow(subject).to receive(:url).and_return(queue_url)
|
194
|
-
allow(sqs).to
|
203
|
+
allow(sqs).to(
|
204
|
+
receive(:get_queue_attributes).with(queue_url: queue_url, attribute_names: ['All']).and_return(attribute_response)
|
205
|
+
)
|
195
206
|
end
|
196
207
|
|
197
208
|
context 'when queue is FIFO' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shoryuken
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Cantero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|