Class: ActiveRecord::ConnectionAdapters::SeamlessDatabasePoolAdapter::AvailableConnections

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/seamless_database_pool_adapter.rb

Overview

This simple class puts an expire time on an array of connections. It is used so the a connection to a down database won't try to reconnect over and over.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connections, failed_connection = nil, expires = nil) ⇒ AvailableConnections

Returns a new instance of AvailableConnections


277
278
279
280
281
# File 'lib/active_record/connection_adapters/seamless_database_pool_adapter.rb', line 277

def initialize(connections, failed_connection = nil, expires = nil)
  @connections = connections
  @failed_connection = failed_connection
  @expires = expires
end

Instance Attribute Details

#connectionsObject (readonly)

Returns the value of attribute connections


274
275
276
# File 'lib/active_record/connection_adapters/seamless_database_pool_adapter.rb', line 274

def connections
  @connections
end

#expires=(value) ⇒ Object (writeonly)

Sets the attribute expires

Parameters:

  • value

    the value to set the attribute expires to.


275
276
277
# File 'lib/active_record/connection_adapters/seamless_database_pool_adapter.rb', line 275

def expires=(value)
  @expires = value
end

#failed_connectionObject (readonly)

Returns the value of attribute failed_connection


274
275
276
# File 'lib/active_record/connection_adapters/seamless_database_pool_adapter.rb', line 274

def failed_connection
  @failed_connection
end

Instance Method Details

#expired?Boolean

Returns:

  • (Boolean)

283
284
285
# File 'lib/active_record/connection_adapters/seamless_database_pool_adapter.rb', line 283

def expired?
  @expires ? @expires <= Time.now : false
end

#reconnect!Object


287
288
289
290
# File 'lib/active_record/connection_adapters/seamless_database_pool_adapter.rb', line 287

def reconnect!
  failed_connection.reconnect!
  raise DatabaseConnectionError.new unless failed_connection.active?
end