shoryuken 3.1.1 → 3.1.2
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/CHANGELOG.md +6 -1
- data/lib/shoryuken/launcher.rb +2 -3
- data/lib/shoryuken/manager.rb +18 -21
- data/lib/shoryuken/processor.rb +4 -0
- data/lib/shoryuken/version.rb +1 -1
- data/spec/shoryuken/manager_spec.rb +30 -17
- 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: 53d21819575a7b12f3697e5c06b390519f164baa
|
4
|
+
data.tar.gz: 967d57ff341f98b950661ca8d249b90a044ca08a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a00ede2ec62aa8be31528aed16634bd1e99f04d5be4345b36fd1fa0c9baf01131a45ad6559c87a5f37432c95ca21a8a0d00060b85c9c60b94d4a7c3e01e0f651
|
7
|
+
data.tar.gz: 1fe49809c4a90e468a945979aebb1407f55d32a681788e882c82d08482dd768c571fe8e229dc3677ae6aeece348477fbd944ff7d04f80bdae7f8e258a35a6de3
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
|
-
## [v3.1.
|
1
|
+
## [v3.1.2] - 2017-07-06
|
2
|
+
|
3
|
+
- Fix stack level too deep on Ubuntu
|
4
|
+
- [#400](https://github.com/phstc/shoryuken/pull/400)
|
5
|
+
|
6
|
+
## [v3.1.1] - 2017-07-05
|
2
7
|
|
3
8
|
- Reduce log verbosity introduced in 3.1.0
|
4
9
|
- [#397](https://github.com/phstc/shoryuken/pull/397)
|
data/lib/shoryuken/launcher.rb
CHANGED
@@ -62,8 +62,6 @@ module Shoryuken
|
|
62
62
|
def initiate_stop
|
63
63
|
logger.info { 'Shutting down' }
|
64
64
|
|
65
|
-
@managers.each(&:stop)
|
66
|
-
|
67
65
|
stop_callback
|
68
66
|
end
|
69
67
|
|
@@ -90,7 +88,8 @@ module Shoryuken
|
|
90
88
|
Shoryuken::Manager.new(
|
91
89
|
Shoryuken::Fetcher.new(group),
|
92
90
|
Shoryuken.polling_strategy(group).new(options[:queues]),
|
93
|
-
options[:concurrency]
|
91
|
+
options[:concurrency],
|
92
|
+
executor
|
94
93
|
)
|
95
94
|
end
|
96
95
|
end
|
data/lib/shoryuken/manager.rb
CHANGED
@@ -6,33 +6,37 @@ module Shoryuken
|
|
6
6
|
# See https://github.com/phstc/shoryuken/issues/348#issuecomment-292847028
|
7
7
|
MIN_DISPATCH_INTERVAL = 0.1
|
8
8
|
|
9
|
-
def initialize(fetcher, polling_strategy, concurrency)
|
9
|
+
def initialize(fetcher, polling_strategy, concurrency, executor)
|
10
10
|
@fetcher = fetcher
|
11
11
|
@polling_strategy = polling_strategy
|
12
12
|
@max_processors = concurrency
|
13
13
|
@busy_processors = Concurrent::AtomicFixnum.new(0)
|
14
|
-
@
|
14
|
+
@executor = executor
|
15
15
|
end
|
16
16
|
|
17
17
|
def start
|
18
|
-
|
18
|
+
dispatch_loop
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
21
|
+
private
|
22
|
+
|
23
|
+
def running?
|
24
|
+
@executor.running?
|
23
25
|
end
|
24
26
|
|
25
|
-
|
27
|
+
def dispatch_loop
|
28
|
+
return unless running?
|
26
29
|
|
27
|
-
|
28
|
-
|
30
|
+
Concurrent::Promise.execute(
|
31
|
+
executor: @executor
|
32
|
+
) { dispatch }.then { dispatch_loop }.rescue { |ex| raise ex }
|
29
33
|
end
|
30
34
|
|
31
35
|
def dispatch
|
32
|
-
return
|
36
|
+
return unless running?
|
33
37
|
|
34
38
|
if ready <= 0 || (queue = @polling_strategy.next_queue).nil?
|
35
|
-
return
|
39
|
+
return sleep(MIN_DISPATCH_INTERVAL)
|
36
40
|
end
|
37
41
|
|
38
42
|
fire_event(:dispatch)
|
@@ -40,13 +44,6 @@ module Shoryuken
|
|
40
44
|
logger.debug { "Ready: #{ready}, Busy: #{busy}, Active Queues: #{@polling_strategy.active_queues}" }
|
41
45
|
|
42
46
|
batched_queue?(queue) ? dispatch_batch(queue) : dispatch_single_messages(queue)
|
43
|
-
|
44
|
-
dispatch
|
45
|
-
end
|
46
|
-
|
47
|
-
def dispatch_later
|
48
|
-
sleep(MIN_DISPATCH_INTERVAL)
|
49
|
-
dispatch
|
50
47
|
end
|
51
48
|
|
52
49
|
def busy
|
@@ -62,15 +59,15 @@ module Shoryuken
|
|
62
59
|
end
|
63
60
|
|
64
61
|
def assign(queue_name, sqs_msg)
|
65
|
-
return
|
62
|
+
return unless running?
|
66
63
|
|
67
64
|
logger.debug { "Assigning #{sqs_msg.message_id}" }
|
68
65
|
|
69
66
|
@busy_processors.increment
|
70
67
|
|
71
|
-
Concurrent::Promise.execute
|
72
|
-
|
73
|
-
}.then { processor_done }.rescue { processor_done }
|
68
|
+
Concurrent::Promise.execute(
|
69
|
+
executor: @executor
|
70
|
+
) { Processor.process(queue_name, sqs_msg) }.then { processor_done }.rescue { processor_done }
|
74
71
|
end
|
75
72
|
|
76
73
|
def dispatch_batch(queue)
|
data/lib/shoryuken/processor.rb
CHANGED
data/lib/shoryuken/version.rb
CHANGED
@@ -13,8 +13,9 @@ RSpec.describe Shoryuken::Manager do
|
|
13
13
|
let(:polling_strategy) { Shoryuken::Polling::WeightedRoundRobin.new(queues) }
|
14
14
|
let(:fetcher) { double Shoryuken::Fetcher }
|
15
15
|
let(:concurrency) { 1 }
|
16
|
+
let(:executor) { Concurrent::ImmediateExecutor.new }
|
16
17
|
|
17
|
-
subject { Shoryuken::Manager.new(fetcher, polling_strategy, concurrency) }
|
18
|
+
subject { Shoryuken::Manager.new(fetcher, polling_strategy, concurrency, executor) }
|
18
19
|
|
19
20
|
before do
|
20
21
|
allow(fetcher).to receive(:fetch).and_return([])
|
@@ -27,9 +28,9 @@ RSpec.describe Shoryuken::Manager do
|
|
27
28
|
|
28
29
|
describe '#stop' do
|
29
30
|
specify do
|
30
|
-
allow(subject).to receive(:
|
31
|
-
expect(subject).to receive(:dispatch).
|
32
|
-
expect(subject).to receive(:
|
31
|
+
allow(subject).to receive(:running?).and_return(true, true, false)
|
32
|
+
expect(subject).to receive(:dispatch).once.and_call_original
|
33
|
+
expect(subject).to receive(:dispatch_loop).twice.and_call_original
|
33
34
|
subject.start
|
34
35
|
end
|
35
36
|
end
|
@@ -37,12 +38,12 @@ RSpec.describe Shoryuken::Manager do
|
|
37
38
|
describe '#start' do
|
38
39
|
before do
|
39
40
|
# prevent dispatch loop
|
40
|
-
allow(subject).to receive(:
|
41
|
+
allow(subject).to receive(:running?).and_return(true, true, false)
|
41
42
|
end
|
42
43
|
|
43
44
|
it 'pauses when there are no active queues' do
|
44
45
|
expect(polling_strategy).to receive(:next_queue).and_return(nil)
|
45
|
-
expect(subject).to receive(:
|
46
|
+
expect(subject).to receive(:dispatch).and_call_original
|
46
47
|
subject.start
|
47
48
|
end
|
48
49
|
|
@@ -59,24 +60,36 @@ RSpec.describe Shoryuken::Manager do
|
|
59
60
|
end
|
60
61
|
|
61
62
|
describe '#dispatch' do
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
before do
|
64
|
+
allow(subject).to receive(:running?).and_return(true, true, false)
|
65
|
+
end
|
65
66
|
|
67
|
+
specify do
|
68
|
+
message = ['test1']
|
69
|
+
messages = [message]
|
70
|
+
q = Shoryuken::Polling::QueueConfiguration.new(queue, {})
|
71
|
+
|
72
|
+
expect(fetcher).to receive(:fetch).with(q, concurrency).and_return(messages)
|
66
73
|
expect(subject).to receive(:fire_event).with(:dispatch)
|
74
|
+
expect(Shoryuken::Processor).to receive(:process).with(q, message)
|
67
75
|
expect(Shoryuken.logger).to_not receive(:info)
|
68
76
|
|
69
77
|
subject.send(:dispatch)
|
70
78
|
end
|
71
|
-
end
|
72
79
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
+
context 'when batch' do
|
81
|
+
specify do
|
82
|
+
messages = %w(test1 test2 test3)
|
83
|
+
q = Shoryuken::Polling::QueueConfiguration.new(queue, {})
|
84
|
+
|
85
|
+
expect(fetcher).to receive(:fetch).with(q, described_class::BATCH_LIMIT).and_return(messages)
|
86
|
+
expect(subject).to receive(:fire_event).with(:dispatch)
|
87
|
+
allow(subject).to receive(:batched_queue?).with(q).and_return(true)
|
88
|
+
expect(Shoryuken::Processor).to receive(:process).with(q, messages)
|
89
|
+
expect(Shoryuken.logger).to_not receive(:info)
|
90
|
+
|
91
|
+
subject.send(:dispatch)
|
92
|
+
end
|
80
93
|
end
|
81
94
|
end
|
82
95
|
|
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.2
|
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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|