pools 0.1.6 → 0.1.7
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/pools/connection_pool.rb +16 -10
- 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: 70a334b882b61ca1b32aec8d628d2374caf93c45
|
|
4
|
+
data.tar.gz: b857dfbedbeaea85e88eae1199a4a5c586c4bc5f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1a71428a4b1e7a76d35b02ddd1d4ed951776e6a7d8cc32e92dbe8d6b7d918aff3f543a8358cdc247b78104ebe5be967bbbdc39ad1217b3784b52d612c118b8c9
|
|
7
|
+
data.tar.gz: f0a6155dae531c56a789dc36d2719018bf608dc76218d6d4470874c983b43ca81295979608ff6c557095e9383638c4828fd487706fb592d4ff1c00abc4740ffb
|
|
@@ -95,15 +95,19 @@ module Pools
|
|
|
95
95
|
# #connection can be called any number of times; the connection is
|
|
96
96
|
# held in a hash keyed by the thread id.
|
|
97
97
|
def connection
|
|
98
|
-
@reserved_connections[current_connection_id]
|
|
98
|
+
@reserved_connections[current_connection_id] || synchronize do
|
|
99
|
+
@reserved_connections[current_connection_id] ||= checkout
|
|
100
|
+
end
|
|
99
101
|
end
|
|
100
102
|
|
|
101
103
|
# Signal that the thread is finished with the current connection.
|
|
102
104
|
# #release_connection releases the connection-thread association
|
|
103
105
|
# and returns the connection to the pool.
|
|
104
106
|
def release_connection(with_id = current_connection_id)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
synchronize do
|
|
108
|
+
conn = @reserved_connections.delete(with_id)
|
|
109
|
+
checkin conn if conn
|
|
110
|
+
end
|
|
107
111
|
end
|
|
108
112
|
|
|
109
113
|
# If a connection already exists yield it to the block. If no connection
|
|
@@ -111,7 +115,7 @@ module Pools
|
|
|
111
115
|
# connection when finished.
|
|
112
116
|
def with_connection
|
|
113
117
|
connection_id = current_connection_id
|
|
114
|
-
fresh_connection =
|
|
118
|
+
fresh_connection = synchronize { !@reserved_connections[connection_id] }
|
|
115
119
|
yield connection
|
|
116
120
|
ensure
|
|
117
121
|
release_connection(connection_id) if fresh_connection
|
|
@@ -148,12 +152,14 @@ module Pools
|
|
|
148
152
|
# Return any checked-out connections back to the pool by threads that
|
|
149
153
|
# are no longer alive.
|
|
150
154
|
def clear_stale_cached_connections!
|
|
151
|
-
|
|
152
|
-
t
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
synchronize do
|
|
156
|
+
keys = @reserved_connections.keys - Thread.list.find_all { |t|
|
|
157
|
+
t.alive?
|
|
158
|
+
}.map { |thread| thread.object_id }
|
|
159
|
+
keys.each do |key|
|
|
160
|
+
checkin @reserved_connections[key]
|
|
161
|
+
@reserved_connections.delete(key)
|
|
162
|
+
end
|
|
157
163
|
end
|
|
158
164
|
end
|
|
159
165
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Rykov
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-02-
|
|
11
|
+
date: 2015-02-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|