action_subscriber 3.0.1 → 3.0.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: b5c70aa42049754f97b6f3e05f1fbdc743a728f7
4
- data.tar.gz: e25c7a771fc3f230e194c284ed9f0535a0297bd7
3
+ metadata.gz: bf91f9b2566e00305d9bcc1bb873c550390f29ad
4
+ data.tar.gz: e523407919e74f5af41f321e4a2bc64d00bcaf59
5
5
  SHA512:
6
- metadata.gz: d56c9dbbbf4db7fd0cec44d9a1afbdad0c5f3859b0be64dd800070d60f82aefc65af05cbe6346a252fc9d0aa76f37013ceae20d3f98c0478bf064eb5539c0d17
7
- data.tar.gz: cb838fe0f9f956eea5dd7057ce14827b5f6de5daeab57a0391f84e0f74bea12f0515e7147ff5ed83e8f0f96c907667fe3434eb0f8635f9b2a191b70c939ca7a6
6
+ metadata.gz: f4d5e7566aabf121149d7d2eb453f8892872b268e018a07b6afbada975ce1dcd132307d54a35416077413f8b05174bdd0e0eae869e15a96f7cf4b2bcb8a1aab3
7
+ data.tar.gz: 13c8d270b87969981b92f9777cde802ad1acc9b85c5d68577105730746561f6bc72de1d055efd0956a9cb9e5482dcbb1bf2930a147078af29ead94c6163c463a
@@ -101,6 +101,12 @@ module ActionSubscriber
101
101
  route_set.cancel_consumers!
102
102
  end
103
103
 
104
+ def self.wait_for_threadpools_to_finish_with_timeout(timeout)
105
+ puts "waiting for threadpools to empty (maximum wait of #{::ActionSubscriber.configuration.seconds_to_wait_for_graceful_shutdown}sec)"
106
+ ::ActionSubscriber::Threadpool.wait_to_finish_with_timeout(timeout)
107
+ route_set.wait_to_finish_with_timeout(timeout)
108
+ end
109
+
104
110
  # Execution is delayed until after app loads when used with bin/action_subscriber
105
111
  require "action_subscriber/railtie" if defined?(Rails)
106
112
  ::ActiveSupport.run_load_hooks(:action_subscriber, Base)
@@ -70,20 +70,12 @@ module ActionSubscriber
70
70
  def self.stop_server!
71
71
  # this method is called from within a TRAP context so we can't use the logger
72
72
  puts "Stopping server..."
73
- wait_loops = 0
74
73
  ::ActionSubscriber::Babou.stop_receving_messages!
75
-
76
- while ::ActionSubscriber::Threadpool.busy? && wait_loops < ::ActionSubscriber.configuration.seconds_to_wait_for_graceful_shutdown
77
- puts "waiting for threadpools to empty:"
78
- ::ActionSubscriber::Threadpool.pools.each do |name, pool|
79
- puts " -- #{name} (remaining: #{pool.busy_size})" if pool.busy_size > 0
80
- end
81
- Thread.pass
82
- wait_loops = wait_loops + 1
83
- sleep 1
84
- end
85
-
86
- puts "threadpool empty. Shutting down"
74
+ ::ActionSubscriber.wait_for_threadpools_to_finish_with_timeout(::ActionSubscriber.configuration.seconds_to_wait_for_graceful_shutdown)
75
+ puts "Shutting down"
76
+ ::Thread.new do
77
+ ::ActionSubscriber::RabbitConnection.subscriber_disconnect!
78
+ end.join
87
79
  end
88
80
  end
89
81
  end
@@ -73,6 +73,15 @@ module ActionSubscriber
73
73
  end
74
74
  end
75
75
 
76
+ def wait_to_finish_with_timeout(timeout)
77
+ puts <<-MSG
78
+ Currently bunny doesn't have any sort of a graceful shutdown or
79
+ the ability to check on the status of its ConsumerWorkPool objects.
80
+ For now we just wait for #{timeout}sec to let the worker pools drain.
81
+ MSG
82
+ sleep(timeout)
83
+ end
84
+
76
85
  private
77
86
 
78
87
  def enqueue_env(threadpool, env)
@@ -76,6 +76,26 @@ module ActionSubscriber
76
76
  @march_hare_consumers ||= []
77
77
  end
78
78
 
79
+ def wait_to_finish_with_timeout(timeout)
80
+ wait_loops = 0
81
+ loop do
82
+ wait_loops = wait_loops + 1
83
+ any_threadpools_busy = false
84
+ ::ActionSubscriber::RabbitConnection.connection_threadpools.each do |name, executor|
85
+ next if executor.get_active_count <= 0
86
+ puts " -- Connection #{name} (remaining: #{executor.get_active_count})"
87
+ any_threadpools_busy = true
88
+ end
89
+ if !any_threadpools_busy
90
+ puts "Connection threadpools empty"
91
+ break
92
+ end
93
+ break if wait_loops >= timeout
94
+ Thread.pass
95
+ sleep 1
96
+ end
97
+ end
98
+
79
99
  private
80
100
 
81
101
  def enqueue_env(threadpool, env)
@@ -5,6 +5,16 @@ module ActionSubscriber
5
5
  SUBSCRIBER_CONNECTION_MUTEX = ::Mutex.new
6
6
  NETWORK_RECOVERY_INTERVAL = 1.freeze
7
7
 
8
+ def self.connection_threadpools
9
+ if ::RUBY_PLATFORM == "java"
10
+ subscriber_connections.each_with_object({}) do |(name, connection), hash|
11
+ hash[name] = connection.instance_variable_get("@executor")
12
+ end
13
+ else
14
+ [] # TODO can I get a hold of the thredpool that bunny uses?
15
+ end
16
+ end
17
+
8
18
  def self.setup_connection(name, settings)
9
19
  SUBSCRIBER_CONNECTION_MUTEX.synchronize do
10
20
  fail ArgumentError, "a #{name} connection already exists" if subscriber_connections[name]
@@ -38,5 +38,25 @@ module ActionSubscriber
38
38
  total_ready + [0, pool.pool_size - pool.busy_size].max
39
39
  end
40
40
  end
41
+
42
+ def self.wait_to_finish_with_timeout(timeout)
43
+ wait_loops = 0
44
+ loop do
45
+ wait_loops = wait_loops + 1
46
+ any_threadpools_busy = false
47
+ pools.each do |name, pool|
48
+ next if pool.busy_size <= 0
49
+ puts " -- #{name} (remaining: #{pool.busy_size})"
50
+ any_threadpools_busy = true
51
+ end
52
+ if !any_threadpools_busy
53
+ puts " -- Lifeguard threadpools empty"
54
+ break
55
+ end
56
+ break if wait_loops >= timeout
57
+ Thread.pass
58
+ sleep 1
59
+ end
60
+ end
41
61
  end
42
62
  end
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "3.0.1"
2
+ VERSION = "3.0.2"
3
3
  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: 3.0.1
4
+ version: 3.0.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-09-23 00:00:00.000000000 Z
15
+ date: 2016-09-26 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport