fiber_connection_pool 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +19 -4
- data/lib/fiber_connection_pool.rb +2 -1
- metadata +20 -15
- checksums.yaml +0 -7
data/README.md
CHANGED
@@ -111,17 +111,28 @@ You have to be aware that the connection instance will remain in the pool, and o
|
|
111
111
|
will surely use it. If the Exception you rescued indicates that the connection should be
|
112
112
|
recreated or treated somehow, there's a way to access that particular connection:
|
113
113
|
|
114
|
+
``` ruby
|
115
|
+
pool = FiberConnectionPool.new(:size => 5){ MyFancyConnection.new }
|
116
|
+
|
117
|
+
# state which exceptions will need treatment
|
118
|
+
pool.treated_exceptions = [ BadQueryMadeMeWorse ]
|
119
|
+
```
|
120
|
+
|
114
121
|
``` ruby
|
115
122
|
begin
|
116
123
|
|
117
124
|
pool.bad_query('will make me worse')
|
118
125
|
|
119
|
-
rescue BadQueryMadeMeWorse
|
126
|
+
rescue BadQueryMadeMeWorse # rescue and treat only classes on 'treated_exceptions'
|
120
127
|
|
121
128
|
pool.with_failed_connection do |connection|
|
122
129
|
puts "Replacing #{connection.inspect} with a new one!"
|
123
130
|
MyFancyConnection.new
|
124
131
|
end
|
132
|
+
|
133
|
+
rescue Exception => ex # do not treat the rest of exceptions
|
134
|
+
|
135
|
+
log ex.to_s # -> 'You have a typo on your sql...'
|
125
136
|
|
126
137
|
end
|
127
138
|
```
|
@@ -130,12 +141,16 @@ The pool saves the connection when it raises an exception on a fiber, and with `
|
|
130
141
|
you execute a block of code over it. It must return a connection instance, and it will be put inside the pool
|
131
142
|
in place of the failed one. It can be the same instance after being fixed, or maybe a new one.
|
132
143
|
The call to `with_failed_connection` must be made from the very same
|
133
|
-
fiber that raised the exception.
|
144
|
+
fiber that raised the exception. The failed connection will be kept out of the pool,
|
145
|
+
and reserved for treatment, only if the exception is one of the given in `treated_exceptions`.
|
146
|
+
Otherwise `with_failed_connection` will raise `NoReservedConnection`.
|
134
147
|
|
135
148
|
Also the reference to the failed connection will be lost after any method execution from that
|
136
|
-
fiber. So you must call `with_failed_connection` before any other method that may acquire a new
|
149
|
+
fiber. So you must call `with_failed_connection` before any other method that may acquire a new
|
150
|
+
instance from the pool.
|
137
151
|
|
138
|
-
Any reference to a failed connection is released when the fiber is dead, but as you must access
|
152
|
+
Any reference to a failed connection is released when the fiber is dead, but as you must access
|
153
|
+
it from the fiber itself, worry should not.
|
139
154
|
|
140
155
|
Save data
|
141
156
|
-------------------
|
@@ -2,7 +2,7 @@ require 'fiber'
|
|
2
2
|
require_relative 'fiber_connection_pool/exceptions'
|
3
3
|
|
4
4
|
class FiberConnectionPool
|
5
|
-
VERSION = '0.2.
|
5
|
+
VERSION = '0.2.2'
|
6
6
|
|
7
7
|
RESERVED_TTL_SECS = 30 # reserved cleanup trigger
|
8
8
|
SAVED_DATA_TTL_SECS = 30 # saved_data cleanup trigger
|
@@ -194,6 +194,7 @@ class FiberConnectionPool
|
|
194
194
|
# If no connection is available, yield the given fiber on the pending array
|
195
195
|
#
|
196
196
|
def acquire(fiber)
|
197
|
+
return @reserved[fiber] if @reserved[fiber] # already reserved? then use it
|
197
198
|
if conn = @available.pop
|
198
199
|
@reserved[fiber] = conn
|
199
200
|
conn
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fiber_connection_pool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Ruben Caro
|
@@ -9,40 +10,43 @@ authors:
|
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
13
|
+
date: 2013-09-03 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: minitest
|
16
17
|
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
17
19
|
requirements:
|
18
|
-
- - '>='
|
20
|
+
- - ! '>='
|
19
21
|
- !ruby/object:Gem::Version
|
20
22
|
version: '0'
|
21
23
|
type: :development
|
22
24
|
prerelease: false
|
23
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
24
27
|
requirements:
|
25
|
-
- - '>='
|
28
|
+
- - ! '>='
|
26
29
|
- !ruby/object:Gem::Version
|
27
30
|
version: '0'
|
28
31
|
- !ruby/object:Gem::Dependency
|
29
32
|
name: rake
|
30
33
|
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
31
35
|
requirements:
|
32
|
-
- - '>='
|
36
|
+
- - ! '>='
|
33
37
|
- !ruby/object:Gem::Version
|
34
38
|
version: '0'
|
35
39
|
type: :development
|
36
40
|
prerelease: false
|
37
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
38
43
|
requirements:
|
39
|
-
- - '>='
|
44
|
+
- - ! '>='
|
40
45
|
- !ruby/object:Gem::Version
|
41
46
|
version: '0'
|
42
|
-
description:
|
43
|
-
|
44
|
-
|
45
|
-
as provided by EventMachine or Celluloid.
|
47
|
+
description: ! "Fiber-based generic connection pool for Ruby, allowing\n non-blocking
|
48
|
+
IO behaviour on the same thread\n as provided by EventMachine or
|
49
|
+
Celluloid."
|
46
50
|
email:
|
47
51
|
- ruben.caro@lanuez.org
|
48
52
|
executables: []
|
@@ -69,26 +73,27 @@ files:
|
|
69
73
|
homepage: https://github.com/rubencaro/fiber_connection_pool
|
70
74
|
licenses:
|
71
75
|
- GPLv3
|
72
|
-
metadata: {}
|
73
76
|
post_install_message:
|
74
77
|
rdoc_options: []
|
75
78
|
require_paths:
|
76
79
|
- lib
|
77
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
78
82
|
requirements:
|
79
|
-
- - '>='
|
83
|
+
- - ! '>='
|
80
84
|
- !ruby/object:Gem::Version
|
81
85
|
version: 1.9.2
|
82
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
83
88
|
requirements:
|
84
|
-
- - '>='
|
89
|
+
- - ! '>='
|
85
90
|
- !ruby/object:Gem::Version
|
86
91
|
version: '0'
|
87
92
|
requirements: []
|
88
93
|
rubyforge_project:
|
89
|
-
rubygems_version:
|
94
|
+
rubygems_version: 1.8.25
|
90
95
|
signing_key:
|
91
|
-
specification_version:
|
96
|
+
specification_version: 3
|
92
97
|
summary: Fiber-based generic connection pool for Ruby
|
93
98
|
test_files:
|
94
99
|
- test/fiber_connection_pool_test.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 9fdb88ab21985a6014912366f1a917da8d0df76c
|
4
|
-
data.tar.gz: cc131028a049c18efc0029e63e83966b24cc10b0
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 84abe69a34155bdf1307987d93a4b3c55cd0483be1d55ca0b50fadd8faf42f2582c46a1cada282beb9d245138c71829b00f3e86b8721a553ac75f6c8d1a9e414
|
7
|
-
data.tar.gz: d7f20e3e765f1e334405b0c333c86d63302804318856d2928823f9e10a00dc3015abfb826ccc773e39ab089621d958601301596564d062cfb7162cab7cc9bd3e
|