reconnect!(restore_transactions: false)
public
Disconnects from the database if already connected, and establishes a new
connection with the database. Implementors should define private #reconnect
instead.
Show source
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
@verified = 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)
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
@verified = false
raise translated_exception
end
end