Module: OverSIP::Modules::Postgresql

Extended by:
Logger
Defined in:
lib/oversip-mod-postgresql.rb,
lib/oversip-mod-postgresql/version.rb

Defined Under Namespace

Modules: Version Classes: Pool

Constant Summary collapse

DEFAULT_POOL_SIZE =
10
VERSION =
[Version::MAJOR, Version::MINOR, Version::TINY].join(".")

Class Method Summary collapse

Class Method Details

.add_pool(options) ⇒ Object

Raises:

  • (::ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/oversip-mod-postgresql.rb', line 18

def self.add_pool options
  raise ::ArgumentError, "`options' must be a Hash"  unless options.is_a? ::Hash

  # Avoid the hash to be modified internally.
  options = options.clone
  # Delete options not existing in pg.
  pool_name = options.delete(:pool_name)
  pool_size = options.delete(:pool_size) || DEFAULT_POOL_SIZE

  raise ::ArgumentError, "`options[:pool_name]' must be a Symbol"  unless pool_name.is_a? ::Symbol
  raise ::ArgumentError, "`options[:pool_size]' must be a positive Fixnum"  unless pool_size.is_a? ::Fixnum and pool_size > 0

  block = ::Proc.new  if block_given?

  ::OverSIP::SystemCallbacks.on_started do
    log_info "Adding PostgreSQL connection pool (name: #{pool_name.inspect}, size: #{pool_size})..."
    @pools[pool_name] = Pool.new pool_size, options, block
  end
end

.pool(pool_name) ⇒ Object Also known as: get_pool

def self.add_pool

Raises:

  • (::ArgumentError)


38
39
40
41
42
# File 'lib/oversip-mod-postgresql.rb', line 38

def self.pool pool_name
  pool = @pools[pool_name]
  raise ::ArgumentError, "no pool with `name' #{pool_name.inspect}"  unless pool
  pool
end