class Flounder::ConnectionPool

Constants

Spec

Attributes

pg_conn_args[R]

Public Class Methods

new(pg_conn_args) click to toggle source
# File lib/flounder/connection_pool.rb, line 7
def initialize pg_conn_args
  @pg_conn_args = pg_conn_args
  @pool = ::ConnectionPool.new(size: 5, timeout: 5) {
    Connection.new(pg_conn_args)
  }
end

Public Instance Methods

checkout() click to toggle source

Checks out a connection from the pool. You have to return this connection manually.

# File lib/flounder/connection_pool.rb, line 27
def checkout
  @pool.checkout
end
spec() click to toggle source

This is needed to conform to arels interface.

# File lib/flounder/connection_pool.rb, line 35
def spec
  Spec.new(adapter: 'pg')
end
with_connection() { |conn| ... } click to toggle source

Checks out a connection from the pool and yields it to the block. The connection is returned to the pool at the end of the block; don’t hold on to it.

# File lib/flounder/connection_pool.rb, line 18
def with_connection
  @pool.with do |conn|
    yield conn
  end
end