Class: NewRelic::Agent::Database::ConnectionManager

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

Instance Method Summary collapse

Instance Method Details

#close_connectionsObject

Closes all the connections in the internal connection cache



167
168
169
170
171
172
173
174
175
176
177
# File 'lib/new_relic/agent/database.rb', line 167

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

  @connections = {}
end

#get_connection(config) ⇒ Object

Returns a cached connection for a given ActiveRecord configuration - these are stored or reopened as needed, and if we cannot get one, we ignore it and move on without explaining the sql



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/new_relic/agent/database.rb', line 150

def get_connection(config)
  @connections ||= {}

  connection = @connections[config]

  return connection if connection

  begin
    connection = ActiveRecord::Base.send("#{config[:adapter]}_connection", config)
    @connections[config] = connection
  rescue => e
    ::NewRelic::Agent.logger.error("Caught exception trying to get connection to DB for explain. Control: #{config}", e)
    nil
  end
end