oversip-mod-postgresql 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/lib/oversip-mod-postgresql.rb +35 -10
- data/lib/oversip-mod-postgresql/version.rb +2 -2
- metadata +4 -4
data/LICENSE
CHANGED
@@ -31,7 +31,24 @@ module OverSIP
|
|
31
31
|
|
32
32
|
::OverSIP::SystemCallbacks.on_started do
|
33
33
|
log_info "Adding PostgreSQL connection pool (name: #{pool_name.inspect}, size: #{pool_size})..."
|
34
|
-
@pools[pool_name] =
|
34
|
+
@pools[pool_name] = Pool.new pool_size, options, block
|
35
|
+
end
|
36
|
+
end # def self.add_pool
|
37
|
+
|
38
|
+
def self.pool pool_name
|
39
|
+
pool = @pools[pool_name]
|
40
|
+
raise ::ArgumentError, "no pool with `name' #{pool_name.inspect}" unless pool
|
41
|
+
pool
|
42
|
+
end
|
43
|
+
class << self
|
44
|
+
alias :get_pool :pool
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
class Pool
|
49
|
+
|
50
|
+
def initialize pool_size, options, block
|
51
|
+
@em_synchrony_connectionpool = ::EM::Synchrony::ConnectionPool.new(size: pool_size) do
|
35
52
|
# Avoid the hash to be modified by PG::EM::Client.
|
36
53
|
options = options.clone
|
37
54
|
# Force DB autoreconnect.
|
@@ -44,16 +61,24 @@ module OverSIP
|
|
44
61
|
conn
|
45
62
|
end
|
46
63
|
end
|
47
|
-
end
|
48
64
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
65
|
+
def method_missing method, *args, &blk
|
66
|
+
@em_synchrony_connectionpool.__send__ method, *args, &blk
|
67
|
+
end
|
68
|
+
|
69
|
+
def query *args, &blk
|
70
|
+
# If we are not in the OverSIP Root Fiber then do nothing special.
|
71
|
+
if ::Fiber.current != ::OverSIP.root_fiber
|
72
|
+
@em_synchrony_connectionpool.__send__ :query, *args, &blk
|
73
|
+
# Otherwise run the query within a new Fiber.
|
74
|
+
else
|
75
|
+
::Fiber.new do
|
76
|
+
@em_synchrony_connectionpool.__send__ :query, *args, &blk
|
77
|
+
end.resume
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end # class Pool
|
57
82
|
|
58
83
|
end # module Postgresql
|
59
84
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oversip-mod-postgresql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oversip
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.3.
|
21
|
+
version: 1.3.7
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.3.
|
29
|
+
version: 1.3.7
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: em-pg-client
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|