Class: NewRelic::Agent::Database::ConnectionManager
- Inherits:
-
Object
- Object
- NewRelic::Agent::Database::ConnectionManager
- Includes:
- Singleton
- Defined in:
- lib/new_relic/agent/database.rb
Instance Method Summary collapse
-
#close_connections ⇒ Object
Closes all the connections in the internal connection cache.
- #discard_connection(config) ⇒ Object
-
#get_connection(config, &connector) ⇒ 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.
-
#reset_or_discard_connection(config, connection) ⇒ Object
connection.reset! rolls back any open transaction; if that itself fails, evict it.
Instance Method Details
#close_connections ⇒ Object
Closes all the connections in the internal connection cache
240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/new_relic/agent/database.rb', line 240 def close_connections @connections ||= {} @connections.values.each do |connection| begin connection.disconnect! rescue end end @connections = {} end |
#discard_connection(config) ⇒ Object
228 229 230 231 232 233 234 235 236 237 |
# File 'lib/new_relic/agent/database.rb', line 228 def discard_connection(config) @connections ||= {} connection = @connections.delete(config) return unless connection begin connection.disconnect! rescue end end |
#get_connection(config, &connector) ⇒ 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
206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/new_relic/agent/database.rb', line 206 def get_connection(config, &connector) @connections ||= {} connection = @connections[config] return connection if connection begin @connections[config] = yield(config) rescue => e ::NewRelic::Agent.logger.error('Caught exception trying to get connection to DB for explain.', e) nil end end |
#reset_or_discard_connection(config, connection) ⇒ Object
connection.reset! rolls back any open transaction; if that itself fails, evict it.
222 223 224 225 226 |
# File 'lib/new_relic/agent/database.rb', line 222 def reset_or_discard_connection(config, connection) connection.reset! rescue discard_connection(config) end |