Class: PgBouncerHero::Connection
- Inherits:
-
Object
- Object
- PgBouncerHero::Connection
- Defined in:
- lib/pgbouncerhero/connection.rb
Instance Method Summary collapse
- #connection ⇒ Object
-
#initialize(host, port, user, password, dbname) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(host, port, user, password, dbname) ⇒ Connection
Returns a new instance of Connection.
4 5 6 7 8 9 10 11 |
# File 'lib/pgbouncerhero/connection.rb', line 4 def initialize(host, port, user, password, dbname) @host = host @port = port @user = user @password = password @dbname = dbname @timeout = ENV["PGBOUNCERHERO_TIMEOUT"] || 5 end |
Instance Method Details
#connection ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pgbouncerhero/connection.rb', line 13 def connection @connection ||= begin begin PG.connect( host: @host, port: @port, user: @user, password: @password, dbname: @dbname, connect_timeout: @timeout ) rescue Exception => e Rails.logger.error("[PGBouncerHero] Host:#{@host} | Database Name:#{@dbname} | Timeout: #{@timeout}s => #{e}") nil end end end |