Class: ActiveRecord::ConnectionAdapters::MariaDbClusterPoolAdapter::AvailableConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/maria_db_cluster_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(connection, failed_connection = false, expires = nil) ⇒ AvailableConnection



185
186
187
188
189
# File 'lib/active_record/connection_adapters/maria_db_cluster_pool_adapter.rb', line 185

def initialize(connection, failed_connection = false, expires = nil)
  @connection = connection
  @failed_connection = failed_connection
  @expires = expires
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



181
182
183
# File 'lib/active_record/connection_adapters/maria_db_cluster_pool_adapter.rb', line 181

def connection
  @connection
end

#expires=(value) ⇒ Object (writeonly)

Sets the attribute expires



183
184
185
# File 'lib/active_record/connection_adapters/maria_db_cluster_pool_adapter.rb', line 183

def expires=(value)
  @expires = value
end

#failed_connection=(value) ⇒ Object (writeonly)

Sets the attribute failed_connection



182
183
184
# File 'lib/active_record/connection_adapters/maria_db_cluster_pool_adapter.rb', line 182

def failed_connection=(value)
  @failed_connection = value
end

Instance Method Details

#expired?Boolean



191
192
193
# File 'lib/active_record/connection_adapters/maria_db_cluster_pool_adapter.rb', line 191

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

#failed?Boolean



195
196
197
# File 'lib/active_record/connection_adapters/maria_db_cluster_pool_adapter.rb', line 195

def failed?
  @failed_connection
end

#reconnect!Object



199
200
201
202
203
204
205
206
207
# File 'lib/active_record/connection_adapters/maria_db_cluster_pool_adapter.rb', line 199

def reconnect!
  @connection.reconnect!
  if @connection.active?
    @failed_connection = false
    @expires = nil
  else
    raise DatabaseConnectionError.new
  end
end