Module: Exekutor::Internal::DatabaseConnection
- Defined in:
- lib/exekutor/internal/database_connection.rb
Overview
Helper methods for the DB connection name
Class Method Summary collapse
-
.application_name(id, process = nil) ⇒ Object
The connection name for the specified worker id and process.
-
.ensure_active!(connection = BaseRecord.connection) ⇒ Object
Reconnects the database if it is not active.
-
.set_application_name(pg_conn, id, process = nil) ⇒ Object
Sets the connection name.
Class Method Details
.application_name(id, process = nil) ⇒ Object
The connection name for the specified worker id and process
16 17 18 |
# File 'lib/exekutor/internal/database_connection.rb', line 16 def self.application_name(id, process = nil) "Exekutor[id: #{id}]#{" #{process}" if process}" end |
.ensure_active!(connection = BaseRecord.connection) ⇒ Object
Reconnects the database if it is not active
22 23 24 |
# File 'lib/exekutor/internal/database_connection.rb', line 22 def self.ensure_active!(connection = BaseRecord.connection) connection.reconnect! unless connection.active? end |
.set_application_name(pg_conn, id, process = nil) ⇒ Object
Sets the connection name
9 10 11 |
# File 'lib/exekutor/internal/database_connection.rb', line 9 def self.set_application_name(pg_conn, id, process = nil) pg_conn.exec("SET application_name = #{pg_conn.escape_identifier(application_name(id, process))}") end |