action_subscriber 3.0.1-java → 3.0.2-java
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/lib/action_subscriber.rb +6 -0
- data/lib/action_subscriber/babou.rb +5 -13
- data/lib/action_subscriber/bunny/subscriber.rb +9 -0
- data/lib/action_subscriber/march_hare/subscriber.rb +20 -0
- data/lib/action_subscriber/rabbit_connection.rb +10 -0
- data/lib/action_subscriber/threadpool.rb +20 -0
- data/lib/action_subscriber/version.rb +1 -1
- 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: d672ec64568bbf5c2a6907b57bd08f0e494367fe
|
4
|
+
data.tar.gz: 97146e4e381cad8acee06f1e96d47e36431d629f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef116de1b2ea6fd6f7662005cf75b1efa73a71e929065d6e81368daa2726de218326dfc2db8da08aa35fdbceb8dba7f0a495e1287c9899a693dfc05c6c98f0dc
|
7
|
+
data.tar.gz: 5ab5b2d3f3daedcfebd25e030bb4059beaf59b64f9810290676cb4bcdf92361ac8c2cb8c9aca90dc559045000464b5e4b9df2f299a60b66eb941bb2a6b0d1baf
|
data/lib/action_subscriber.rb
CHANGED
@@ -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
|
-
|
77
|
-
|
78
|
-
::ActionSubscriber::
|
79
|
-
|
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
|
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.
|
4
|
+
version: 3.0.2
|
5
5
|
platform: java
|
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-
|
15
|
+
date: 2016-09-26 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|