Class: OneApm::Agent::Database::ConnectionManager

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/one_apm/agent/database.rb

Instance Method Summary collapse

Instance Method Details

#close_connectionsObject



263
264
265
266
267
268
269
270
271
272
273
# File 'lib/one_apm/agent/database.rb', line 263

def close_connections
  @connections ||= {}
  @connections.values.each do |connection|
    begin
      connection.disconnect!
    rescue
    end
  end

  @connections = {}
end

#get_connection(config, &connector) ⇒ Object



248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/one_apm/agent/database.rb', line 248

def get_connection(config, &connector)
  @connections ||= {}

  connection = @connections[config]

  return connection if connection

  begin
    @connections[config] = connector.call(config)
  rescue => e
    OneApm::Manager.logger.error("Caught exception trying to get connection to DB for explain.", e)
    nil
  end
end