instance method
reconnect!
Ruby on Rails 8.0.4
Since v2.2.3Signature
reconnect!(restore_transactions: false)
Disconnects from the database if already connected, and establishes a new connection with the database. Implementors should define private #reconnect instead.
Parameters
-
restore_transactionskey = false
Source
# File activerecord/lib/active_record/connection_adapters/abstract_adapter.rb, line 664
def reconnect!(restore_transactions: false)
retries_available = connection_retries
deadline = retry_deadline && Process.clock_gettime(Process::CLOCK_MONOTONIC) + retry_deadline
@lock.synchronize do
reconnect
enable_lazy_transactions!
@raw_connection_dirty = false
@last_activity = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@verified = true
reset_transaction(restore: restore_transactions) do
clear_cache!(new_connection: true)
attempt_configure_connection
end
rescue => original_exception
translated_exception = translate_exception_class(original_exception, nil, nil)
retry_deadline_exceeded = deadline && deadline < Process.clock_gettime(Process::CLOCK_MONOTONIC)
if !retry_deadline_exceeded && retries_available > 0
retries_available -= 1
if retryable_connection_error?(translated_exception)
backoff(connection_retries - retries_available)
retry
end
end
@last_activity = nil
@verified = false
raise translated_exception
end
end
Defined in activerecord/lib/active_record/connection_adapters/abstract_adapter.rb line 664
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::ConnectionAdapters::AbstractAdapter