instance method
reconnect!
Ruby on Rails edge
Signature
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 743
def reconnect!(restore_transactions: false)
budget = build_retry_budget(allow_retry: true, reconnectable: false)
@lock.synchronize do
attempt_configure_connection do
@allow_preconnect = false
reconnect
@needs_reconnect = false
enable_lazy_transactions!
@raw_connection_dirty = false
@last_activity = @connected_since = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@verified = true
@allow_preconnect = true
reset_transaction(restore: restore_transactions) do
clear_cache!(new_connection: true)
configure_connection
end
rescue => original_exception
translated_exception = translate_exception_class(original_exception, nil, nil)
if retryable_connection_error?(translated_exception) && budget.consume
backoff(budget.attempts_used)
retry
end
raise translated_exception
end
end
end
Defined in activerecord/lib/active_record/connection_adapters/abstract_adapter.rb line 743
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::ConnectionAdapters::AbstractAdapter