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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3626c435f7da14e0880fabb7faf65e397aa82e0
4
- data.tar.gz: 37461e552bc0566e3edd7a79a9dbbe92bbdbb5a2
3
+ metadata.gz: 53d21819575a7b12f3697e5c06b390519f164baa
4
+ data.tar.gz: 967d57ff341f98b950661ca8d249b90a044ca08a
5
5
  SHA512:
6
- metadata.gz: 2a0b1138fcfaf8453e9ae9770dd8f70f4d5db75b81c5b66d5ca740cc92eefd585c7c396bce94a6401527c4465a5d8aa3bdfcfa00ab001567491a45c564e0d993
7
- data.tar.gz: 64dfb7449d054cdee861632ca32cf09f47215f400b81025ae5d2481dbcc0ab062e780c6b9a47e23ffb0ae3bf697924b965b7a8e048a7b866535d5dc92021e6c0
6
+ metadata.gz: a00ede2ec62aa8be31528aed16634bd1e99f04d5be4345b36fd1fa0c9baf01131a45ad6559c87a5f37432c95ca21a8a0d00060b85c9c60b94d4a7c3e01e0f651
7
+ data.tar.gz: 1fe49809c4a90e468a945979aebb1407f55d32a681788e882c82d08482dd768c571fe8e229dc3677ae6aeece348477fbd944ff7d04f80bdae7f8e258a35a6de3
@@ -1,4 +1,9 @@
1
- ## [v3.1.1] - 2017-07-02
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)
@@ -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
@@ -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
- @done = Concurrent::AtomicBoolean.new(false)
14
+ @executor = executor
15
15
  end
16
16
 
17
17
  def start
18
- dispatch
18
+ dispatch_loop
19
19
  end
20
20
 
21
- def stop
22
- @done.make_true
21
+ private
22
+
23
+ def running?
24
+ @executor.running?
23
25
  end
24
26
 
25
- private
27
+ def dispatch_loop
28
+ return unless running?
26
29
 
27
- def stopped?
28
- @done.true?
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 if stopped?
36
+ return unless running?
33
37
 
34
38
  if ready <= 0 || (queue = @polling_strategy.next_queue).nil?
35
- return dispatch_later
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 if stopped?
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
- Processor.new(queue_name, sqs_msg).process
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)
@@ -4,6 +4,10 @@ module Shoryuken
4
4
 
5
5
  attr_reader :queue, :sqs_msg
6
6
 
7
+ def self.process(queue, sqs_msg)
8
+ new(queue, sqs_msg).process
9
+ end
10
+
7
11
  def initialize(queue, sqs_msg)
8
12
  @queue = queue
9
13
  @sqs_msg = sqs_msg
@@ -1,3 +1,3 @@
1
1
  module Shoryuken
2
- VERSION = '3.1.1'.freeze
2
+ VERSION = '3.1.2'.freeze
3
3
  end
@@ -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(:stopped?).and_return(false, false, true)
31
- expect(subject).to receive(:dispatch).thrice.and_call_original
32
- expect(subject).to receive(:dispatch_later).once.and_call_original
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(:stopped?).and_return(false, true)
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(:dispatch_later)
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
- it 'fires a dispatch event' do
63
- # prevent dispatch loop
64
- allow(subject).to receive(:stopped?).and_return(false, true)
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
- describe '#dispatch_batch' do
74
- it 'assings batch as a single message' do
75
- q = polling_strategy.next_queue
76
- messages = [1, 2, 3]
77
- expect(fetcher).to receive(:fetch).with(q, described_class::BATCH_LIMIT).and_return(messages)
78
- expect_any_instance_of(described_class).to receive(:assign).with(q.name, messages)
79
- subject.send(:dispatch_batch, q)
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.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-05 00:00:00.000000000 Z
11
+ date: 2017-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler