Class: PgBouncerHero::Database
- Inherits:
-
Object
- Object
- PgBouncerHero::Database
show all
- Includes:
- Methods::Basics
- Defined in:
- lib/pgbouncerhero/database.rb
Constant Summary
collapse
- DEFAULT_POOL_SIZE =
5
- DEFAULT_POOL_TIMEOUT =
5
Methods::Basics::SHUTDOWN_MODES
Instance Attribute Summary collapse
Instance Method Summary
collapse
#clients, #conf, #databases, #lists, #pause, #pools, #reconnect, #reload, #resume, #servers, #shutdown, #state, #stats, #summary, #suspend, #users, #wait_close
Constructor Details
#initialize(group, id, config) ⇒ Database
Returns a new instance of Database.
13
14
15
16
17
18
19
20
21
|
# File 'lib/pgbouncerhero/database.rb', line 13
def initialize(group, id, config)
@id = id
@config = config || {}
@url = URI.parse(@config["url"].to_s)
@group = group
@pool_size = positive_integer_setting("pool_size", "PGBOUNCERHERO_POOL_SIZE", DEFAULT_POOL_SIZE)
@pool_timeout = positive_float_setting("pool_timeout", "PGBOUNCERHERO_POOL_TIMEOUT", DEFAULT_POOL_TIMEOUT)
@pool_monitor = Monitor.new
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
11
12
13
|
# File 'lib/pgbouncerhero/database.rb', line 11
def config
@config
end
|
#group ⇒ Object
Returns the value of attribute group.
11
12
13
|
# File 'lib/pgbouncerhero/database.rb', line 11
def group
@group
end
|
#id ⇒ Object
Returns the value of attribute id.
11
12
13
|
# File 'lib/pgbouncerhero/database.rb', line 11
def id
@id
end
|
#pool_size ⇒ Object
Returns the value of attribute pool_size.
11
12
13
|
# File 'lib/pgbouncerhero/database.rb', line 11
def pool_size
@pool_size
end
|
#pool_timeout ⇒ Object
Returns the value of attribute pool_timeout.
11
12
13
|
# File 'lib/pgbouncerhero/database.rb', line 11
def pool_timeout
@pool_timeout
end
|
Instance Method Details
#connection ⇒ Object
27
28
29
30
|
# File 'lib/pgbouncerhero/database.rb', line 27
def connection
proxy = connection_proxy
proxy if with_connection { true }
end
|
#dbname ⇒ Object
72
73
74
|
# File 'lib/pgbouncerhero/database.rb', line 72
def dbname
@url.path[1..-1] if @url
end
|
#disconnect! ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/pgbouncerhero/database.rb', line 42
def disconnect!
pool = @pool_monitor.synchronize do
current_pool = @connection_pool
@connection_pool = nil
@connection_proxy = nil
current_pool
end
pool&.shutdown(&:disconnect!)
end
|
#host ⇒ Object
52
53
54
|
# File 'lib/pgbouncerhero/database.rb', line 52
def host
@url.host if @url
end
|
#name ⇒ Object
23
24
25
|
# File 'lib/pgbouncerhero/database.rb', line 23
def name
@name ||= id.to_s
end
|
#password ⇒ Object
64
65
66
|
# File 'lib/pgbouncerhero/database.rb', line 64
def password
@url.password if @url
end
|
#port ⇒ Object
56
57
58
|
# File 'lib/pgbouncerhero/database.rb', line 56
def port
@url.port if @url
end
|
#user ⇒ Object
60
61
62
|
# File 'lib/pgbouncerhero/database.rb', line 60
def user
@url.user if @url
end
|
#with_connection ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/pgbouncerhero/database.rb', line 32
def with_connection
pool = connection_pool
pool.with do |managed_connection|
managed_connection.with_connection { |raw_connection| yield raw_connection }
end
rescue ConnectionPool::TimeoutError => e
Rails.logger.error("[PGBouncerHero] #{name} connection pool timed out after #{pool_timeout}s: #{e.message}")
nil
end
|