instance method
checkout
Ruby on Rails 8.0.4
Since v2.2.3Signature
checkout(checkout_timeout = @checkout_timeout)
Check-out a database connection from the pool, indicating that you want to use it. You should call #checkin when you no longer need this.
This is done by either returning and leasing existing connection, or by creating a new connection and leasing it.
If all connections are leased and the pool is at capacity (meaning the number of currently leased connections is greater than or equal to the size limit set), an ActiveRecord::ConnectionTimeoutError exception will be raised.
Returns: an AbstractAdapter object.
Raises:
-
ActiveRecord::ConnectionTimeoutError no connection can be obtained from the pool.
Parameters
-
checkout_timeoutopt = @checkout_timeout
Source
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 551
def checkout(checkout_timeout = @checkout_timeout)
return checkout_and_verify(acquire_connection(checkout_timeout)) unless @pinned_connection
@pinned_connection.lock.synchronize do
synchronize do
# The pinned connection may have been cleaned up before we synchronized, so check if it is still present
if @pinned_connection
@pinned_connection.verify!
# Any leased connection must be in @connections otherwise
# some methods like #connected? won't behave correctly
unless @connections.include?(@pinned_connection)
@connections << @pinned_connection
end
@pinned_connection
else
checkout_and_verify(acquire_connection(checkout_timeout))
end
end
end
end
Defined in activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb line 551
· View on GitHub
· Improve this page
· Find usages on GitHub