action_subscriber 2.1.1 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/action_subscriber.gemspec +1 -1
- data/lib/action_subscriber/babou.rb +5 -2
- data/lib/action_subscriber/bunny/subscriber.rb +3 -0
- data/lib/action_subscriber/march_hare/subscriber.rb +3 -0
- data/lib/action_subscriber/threadpool.rb +4 -4
- data/lib/action_subscriber/version.rb +1 -1
- data/lib/action_subscriber.rb +1 -0
- data/spec/lib/action_subscriber/threadpool_spec.rb +26 -12
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d27515da32650e518b407839d2faac598925427
|
4
|
+
data.tar.gz: 1166ddde96c48ab57b4a7b7aace1effa50778057
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4f9a39a8e6e67721b54da8afca7974aeeab211adc40411bfd1f82ce4f4ac51a78245b20bbd89f57410d279ee3028c4fb080869346d981ccaac49b1124008ddb
|
7
|
+
data.tar.gz: 78c68d7e6072dffd4c85485c04407d46daaaac6354bcde86632f9914468296eee4ec8884a0bcab7e2fad3315389cd74b412baea8141fd7e74213057e87c23bce
|
data/action_subscriber.gemspec
CHANGED
@@ -96,8 +96,11 @@ module ActionSubscriber
|
|
96
96
|
wait_loops = 0
|
97
97
|
::ActionSubscriber::Babou.stop_receving_messages!
|
98
98
|
|
99
|
-
while ::ActionSubscriber::Threadpool.
|
100
|
-
puts "waiting for
|
99
|
+
while ::ActionSubscriber::Threadpool.busy? && wait_loops < ::ActionSubscriber.configuration.seconds_to_wait_for_graceful_shutdown
|
100
|
+
puts "waiting for threadpools to empty:"
|
101
|
+
::ActionSubscriber::Threadpool.pools.each do |name, pool|
|
102
|
+
puts " -- #{name} (remaining: #{pool.busy_size})" if pool.busy_size > 0
|
103
|
+
end
|
101
104
|
Thread.pass
|
102
105
|
wait_loops = wait_loops + 1
|
103
106
|
sleep 1
|
@@ -17,6 +17,9 @@ module ActionSubscriber
|
|
17
17
|
times_to_pop = [::ActionSubscriber::Threadpool.ready_size, ::ActionSubscriber.config.times_to_pop].min
|
18
18
|
times_to_pop.times do
|
19
19
|
queues.each do |route, queue|
|
20
|
+
# Handle busy checks on a per threadpool basis
|
21
|
+
next if route.threadpool.busy?
|
22
|
+
|
20
23
|
delivery_info, properties, encoded_payload = queue.pop(route.queue_subscription_options)
|
21
24
|
next unless encoded_payload # empty queue
|
22
25
|
::ActiveSupport::Notifications.instrument "popped_event.action_subscriber", :payload_size => encoded_payload.bytesize, :queue => queue.name
|
@@ -13,6 +13,9 @@ module ActionSubscriber
|
|
13
13
|
times_to_pop = [::ActionSubscriber::Threadpool.ready_size, ::ActionSubscriber.config.times_to_pop].min
|
14
14
|
times_to_pop.times do
|
15
15
|
queues.each do |route,queue|
|
16
|
+
# Handle busy checks on a per threadpool basis
|
17
|
+
next if route.threadpool.busy?
|
18
|
+
|
16
19
|
metadata, encoded_payload = queue.pop(route.queue_subscription_options)
|
17
20
|
next unless encoded_payload
|
18
21
|
::ActiveSupport::Notifications.instrument "popped_event.action_subscriber", :payload_size => encoded_payload.bytesize, :queue => queue.name
|
@@ -4,15 +4,14 @@ module ActionSubscriber
|
|
4
4
|
# Class Methods
|
5
5
|
#
|
6
6
|
def self.busy?
|
7
|
-
|
8
|
-
pool.pool_size == pool.busy_size
|
9
|
-
end
|
7
|
+
!ready?
|
10
8
|
end
|
11
9
|
|
12
10
|
def self.new_pool(name, pool_size = nil)
|
13
11
|
fail ArgumentError, "#{name} already exists as a threadpool" if pools.key?(name)
|
14
12
|
pool_size ||= ::ActionSubscriber.config.threadpool_size
|
15
13
|
pools[name] = ::Lifeguard::InfiniteThreadpool.new(
|
14
|
+
:name => name,
|
16
15
|
:pool_size => pool_size
|
17
16
|
)
|
18
17
|
end
|
@@ -24,13 +23,14 @@ module ActionSubscriber
|
|
24
23
|
def self.pools
|
25
24
|
@pools ||= {
|
26
25
|
:default => ::Lifeguard::InfiniteThreadpool.new(
|
26
|
+
:name => :default,
|
27
27
|
:pool_size => ::ActionSubscriber.config.threadpool_size
|
28
28
|
)
|
29
29
|
}
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.ready?
|
33
|
-
!busy?
|
33
|
+
pools.any? { |_pool_name, pool| !pool.busy? }
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.ready_size
|
data/lib/action_subscriber.rb
CHANGED
@@ -81,6 +81,7 @@ module ActionSubscriber
|
|
81
81
|
logger.info " -- exchange: #{route.exchange}"
|
82
82
|
logger.info " -- queue: #{route.queue}"
|
83
83
|
logger.info " -- routing_key: #{route.routing_key}"
|
84
|
+
logger.info " -- threadpool: #{route.threadpool.name}, pool_size: #{route.threadpool.pool_size}"
|
84
85
|
end
|
85
86
|
end
|
86
87
|
end
|
@@ -1,32 +1,46 @@
|
|
1
1
|
describe ::ActionSubscriber::Threadpool do
|
2
2
|
describe "busy?" do
|
3
|
-
context "when the
|
3
|
+
context "when the pool is busy" do
|
4
4
|
it "returns true" do
|
5
|
-
allow(::ActionSubscriber::Threadpool
|
6
|
-
expect(::ActionSubscriber::Threadpool
|
5
|
+
allow(::ActionSubscriber::Threadpool).to receive(:ready?).and_return(false)
|
6
|
+
expect(::ActionSubscriber::Threadpool).to be_busy
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
context "when
|
10
|
+
context "when the pool is not busy" do
|
11
11
|
it "returns false" do
|
12
|
-
allow(::ActionSubscriber::Threadpool
|
13
|
-
expect(::ActionSubscriber::Threadpool
|
12
|
+
allow(::ActionSubscriber::Threadpool).to receive(:ready?).and_return(true)
|
13
|
+
expect(::ActionSubscriber::Threadpool).to_not be_busy
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
describe "ready?" do
|
19
|
-
context "when the
|
19
|
+
context "when all the workers are full" do
|
20
20
|
it "returns false" do
|
21
|
-
|
22
|
-
|
21
|
+
::ActionSubscriber::Threadpool.new_pool(:some_dumb_pool, 2)
|
22
|
+
|
23
|
+
::ActionSubscriber::Threadpool.pools.map do |_name, pool|
|
24
|
+
allow(pool).to receive(:busy_size).and_return(pool.pool_size)
|
25
|
+
end
|
26
|
+
|
27
|
+
expect(::ActionSubscriber::Threadpool).to_not be_ready
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
26
|
-
context "when the
|
31
|
+
context "when only one of the workers is full" do
|
27
32
|
it "returns true" do
|
28
|
-
|
29
|
-
|
33
|
+
pool = ::ActionSubscriber::Threadpool.new_pool(:some_other_dumb_pool, 2)
|
34
|
+
allow(pool).to receive(:busy_size).and_return(2)
|
35
|
+
|
36
|
+
expect(::ActionSubscriber::Threadpool).to be_ready
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when there are idle workers" do
|
41
|
+
it "returns true" do
|
42
|
+
allow(::ActionSubscriber::Threadpool.pool).to receive(:busy_size).and_return(1)
|
43
|
+
expect(::ActionSubscriber::Threadpool).to be_ready
|
30
44
|
end
|
31
45
|
end
|
32
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action_subscriber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Stien
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2016-02-
|
15
|
+
date: 2016-02-22 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: activesupport
|
@@ -48,14 +48,14 @@ dependencies:
|
|
48
48
|
requirements:
|
49
49
|
- - ">="
|
50
50
|
- !ruby/object:Gem::Version
|
51
|
-
version:
|
51
|
+
version: 0.0.9
|
52
52
|
type: :runtime
|
53
53
|
prerelease: false
|
54
54
|
version_requirements: !ruby/object:Gem::Requirement
|
55
55
|
requirements:
|
56
56
|
- - ">="
|
57
57
|
- !ruby/object:Gem::Version
|
58
|
-
version:
|
58
|
+
version: 0.0.9
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: middleware
|
61
61
|
requirement: !ruby/object:Gem::Requirement
|