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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9575343e64c1b2390a894e3da791c3622d609a6a
4
- data.tar.gz: 50b81796945c52e733b4ad3024bf9022986deda7
3
+ metadata.gz: 0d27515da32650e518b407839d2faac598925427
4
+ data.tar.gz: 1166ddde96c48ab57b4a7b7aace1effa50778057
5
5
  SHA512:
6
- metadata.gz: fed4d194dd8ff1ecac1be9e89002578eb19d1e7628ee5ae63e3bd1941739cc783b482706be318652b4cbcd6755edb3ff7012d519eca6f9ea57f673b65d1eca93
7
- data.tar.gz: 65de4790022a1b705f13a9a94a175c6dd53b0d85c4cfce1b274ad3657fad25f247e7c59d3b27b78cf551884f1e566ecfdbe14d4d09c0cd82e7f2a40e38d3287a
6
+ metadata.gz: b4f9a39a8e6e67721b54da8afca7974aeeab211adc40411bfd1f82ce4f4ac51a78245b20bbd89f57410d279ee3028c4fb080869346d981ccaac49b1124008ddb
7
+ data.tar.gz: 78c68d7e6072dffd4c85485c04407d46daaaac6354bcde86632f9914468296eee4ec8884a0bcab7e2fad3315389cd74b412baea8141fd7e74213057e87c23bce
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  else
27
27
  spec.add_dependency 'bunny', '>= 1.5.0'
28
28
  end
29
- spec.add_dependency 'lifeguard'
29
+ spec.add_dependency 'lifeguard', '>= 0.0.9'
30
30
  spec.add_dependency 'middleware'
31
31
  spec.add_dependency 'thor'
32
32
 
@@ -96,8 +96,11 @@ module ActionSubscriber
96
96
  wait_loops = 0
97
97
  ::ActionSubscriber::Babou.stop_receving_messages!
98
98
 
99
- while ::ActionSubscriber::Threadpool.pool.busy_size > 0 && wait_loops < ::ActionSubscriber.configuration.seconds_to_wait_for_graceful_shutdown
100
- puts "waiting for threadpool to empty (#{::ActionSubscriber::Threadpool.pool.busy_size})"
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
- pools.any? do |_pool_name, pool|
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
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "2.1.1"
2
+ VERSION = "2.1.2"
3
3
  end
@@ -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 workers are busy" do
3
+ context "when the pool is busy" do
4
4
  it "returns true" do
5
- allow(::ActionSubscriber::Threadpool.pool).to receive(:busy_size).and_return(8)
6
- expect(::ActionSubscriber::Threadpool.busy?).to eq(true)
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 there are idle workers" do
10
+ context "when the pool is not busy" do
11
11
  it "returns false" do
12
- allow(::ActionSubscriber::Threadpool.pool).to receive(:busy_size).and_return(1)
13
- expect(::ActionSubscriber::Threadpool.busy?).to eq(false)
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 pool is busy" do
19
+ context "when all the workers are full" do
20
20
  it "returns false" do
21
- allow(::ActionSubscriber::Threadpool).to receive(:busy?).and_return true
22
- expect(::ActionSubscriber::Threadpool.ready?).to eq(false)
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 pool is not busy" do
31
+ context "when only one of the workers is full" do
27
32
  it "returns true" do
28
- allow(::ActionSubscriber::Threadpool).to receive(:busy?).and_return false
29
- expect(::ActionSubscriber::Threadpool.ready?).to eq(true)
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.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-19 00:00:00.000000000 Z
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: '0'
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: '0'
58
+ version: 0.0.9
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: middleware
61
61
  requirement: !ruby/object:Gem::Requirement