Class: OverSIP::Modules::Postgresql::Pool
- Inherits:
-
Object
- Object
- OverSIP::Modules::Postgresql::Pool
- Defined in:
- lib/oversip-mod-postgresql.rb
Instance Method Summary collapse
-
#initialize(pool_size, options, block) ⇒ Pool
constructor
A new instance of Pool.
- #method_missing(method, *args, &blk) ⇒ Object
- #query(*args, &blk) ⇒ Object
Constructor Details
#initialize(pool_size, options, block) ⇒ Pool
Returns a new instance of Pool.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/oversip-mod-postgresql.rb', line 50 def initialize pool_size, , block @em_synchrony_connectionpool = ::EM::Synchrony::ConnectionPool.new(size: pool_size) do # Avoid the hash to be modified by PG::EM::Client. = .clone # Force DB autoreconnect. [:async_autoreconnect] = true conn = ::PG::EM::Client.new() # Call the given block by passing conn as argument. block.call(conn) if block conn end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &blk) ⇒ Object
65 66 67 |
# File 'lib/oversip-mod-postgresql.rb', line 65 def method_missing method, *args, &blk @em_synchrony_connectionpool.__send__ method, *args, &blk end |
Instance Method Details
#query(*args, &blk) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/oversip-mod-postgresql.rb', line 69 def query *args, &blk # If we are not in the OverSIP Root Fiber then do nothing special. if ::Fiber.current != ::OverSIP.root_fiber @em_synchrony_connectionpool.__send__ :query, *args, &blk # Otherwise run the query within a new Fiber. else ::Fiber.new do @em_synchrony_connectionpool.__send__ :query, *args, &blk end.resume end end |