oversip-mod-mysql 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  Name: oversip-mod-mysql
2
2
  Maintainer: Iñaki Baz Castillo <ibc@aliax.net>
3
- Copyright (c) 2012 Iñaki Baz Castillo <ibc@aliax.net>
3
+ Copyright (c) 2013 Iñaki Baz Castillo <ibc@aliax.net>
4
4
 
5
5
 
6
6
  License: The MIT License
data/README.md CHANGED
@@ -23,7 +23,7 @@ Creates a MySQL connection pool by receiving a mandatory `options` (a `Hash`) wi
23
23
 
24
24
  The method allows passing a block which would be later called by passing as argument each generated `Mysql2::EM::Client` instance.
25
25
 
26
- The created connection pool is an instance of [`EventMachine::Synchrony::ConnectionPool`](https://github.com/igrigorik/em-synchrony/blob/master/lib/em-synchrony/connection_pool.rb).
26
+ The created connection pool accepts calls to any method defined for `Mysql2::EM::Client` class instance.
27
27
 
28
28
 
29
29
  ### Method `OverSIP::Modules::Mysql.pool(pool_name)`
@@ -84,22 +84,6 @@ end
84
84
  ```
85
85
 
86
86
 
87
- ## Notes
88
-
89
- ### SQL queries in events others than OverSIP provides
90
-
91
- If you want to place a SQL query within an event different than those provided by OverSIP (i.e. within a EventMachine `add_timer` or `next_tick` callback) then you need to create a Fiber and place the SQL query there (otherwise "can't yield from root fiber" error will occur):
92
-
93
- ```
94
- EM.add_periodic_timer(2) do
95
- Fiber.new do
96
- pool = OverSIP::M::Mysql.pool(:my_db)
97
- rows = pool.query "SELECT * FROM users"
98
- log_info "online users: #{rows.inspect}"
99
- end
100
- end
101
- ```
102
-
103
87
  ## Limitations
104
88
 
105
89
  [mysql2](https://github.com/brianmario/mysql2) driver has auto reconnection support (which is forced by `oversip-mod-mysql` by setting the field `options[:reconnect] => true`). Unfortunatelly the auto reconnect feature of `mysql2` driver is blocking which means that, in case the MySQL server goes down, OverSIP will get frozen during the auto reconnection attempt.
@@ -32,7 +32,24 @@ module OverSIP
32
32
 
33
33
  ::OverSIP::SystemCallbacks.on_started do
34
34
  log_info "Adding MySQL connection pool (name: #{pool_name.inspect}, size: #{pool_size})..."
35
- @pools[pool_name] = ::EM::Synchrony::ConnectionPool.new(size: pool_size) do
35
+ @pools[pool_name] = Pool.new pool_size, options, block
36
+ end
37
+ end # def self.add_pool
38
+
39
+ def self.pool pool_name
40
+ pool = @pools[pool_name]
41
+ raise ::ArgumentError, "no pool with `name' #{pool_name.inspect}" unless pool
42
+ pool
43
+ end
44
+ class << self
45
+ alias :get_pool :pool
46
+ end
47
+
48
+
49
+ class Pool
50
+
51
+ def initialize pool_size, options, block
52
+ @em_synchrony_connectionpool = ::EM::Synchrony::ConnectionPool.new(size: pool_size) do
36
53
  # Avoid the hash to be modified internally.
37
54
  options = options.clone
38
55
  # Force DB autoreconnect.
@@ -45,16 +62,24 @@ module OverSIP
45
62
  conn
46
63
  end
47
64
  end
48
- end # def self.add_pool
49
65
 
50
- def self.pool pool_name
51
- pool = @pools[pool_name]
52
- raise ::ArgumentError, "no pool with `name' #{pool_name.inspect}" unless pool
53
- pool
54
- end
55
- class << self
56
- alias :get_pool :pool
57
- end
66
+ def method_missing method, *args, &blk
67
+ @em_synchrony_connectionpool.__send__ method, *args, &blk
68
+ end
69
+
70
+ def query *args, &blk
71
+ # If we are not in the OverSIP Root Fiber then do nothing special.
72
+ if ::Fiber.current != ::OverSIP.root_fiber
73
+ @em_synchrony_connectionpool.__send__ :query, *args, &blk
74
+ # Otherwise run the query within a new Fiber.
75
+ else
76
+ ::Fiber.new do
77
+ @em_synchrony_connectionpool.__send__ :query, *args, &blk
78
+ end.resume
79
+ end
80
+ end
81
+
82
+ end # class Pool
58
83
 
59
84
  end # module Mysql
60
85
 
@@ -4,8 +4,8 @@ module OverSIP
4
4
  module Mysql
5
5
  module Version
6
6
  MAJOR = 0
7
- MINOR = 1
8
- TINY = 1
7
+ MINOR = 2
8
+ TINY = 0
9
9
  DEVEL = nil # Set to nil for stable releases.
10
10
  end
11
11
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oversip-mod-mysql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
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-15 00:00:00.000000000 Z
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.0
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.0
29
+ version: 1.3.7
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: mysql2
32
32
  requirement: !ruby/object:Gem::Requirement