Module: Exekutor::Internal::DatabaseConnection

Defined in:
lib/exekutor/internal/database_connection.rb

Overview

Helper methods for the DB connection name

Class Method Summary collapse

Class Method Details

.application_name(id, process = nil) ⇒ Object

The connection name for the specified worker id and process

Parameters:

  • id (String)

    the id of the worker

  • process (nil, String) (defaults to: nil)

    the process name



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

Parameters:

  • connection (ActiveRecord::ConnectionAdapters::AbstractAdapter) (defaults to: BaseRecord.connection)

    the connection adapter to use



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