method
flush
v8.1.1 -
Show latest stable
- Class:
ActiveRecord::ConnectionAdapters::ConnectionPool
flush(minimum_idle = @idle_timeout)public
Disconnect all connections that have been idle for at least minimum_idle seconds. Connections currently checked out, or that were checked in less than minimum_idle seconds ago, are unaffected.
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 727
def flush(minimum_idle = @idle_timeout)
return if minimum_idle.nil?
removed_connections = synchronize do
return if self.discarded?
idle_connections = @connections.select do |conn|
!conn.in_use? && conn.seconds_idle >= minimum_idle
end.sort_by { |conn| -conn.seconds_idle } # sort longest idle first
# Don't go below our configured pool minimum unless we're flushing
# everything
idles_to_retain =
if minimum_idle > 0
@min_connections - (@connections.size - idle_connections.size)
else
0
end
if idles_to_retain > 0
idle_connections.pop idles_to_retain
end
idle_connections.each do |conn|
conn.lease
@available.delete conn
@connections.delete conn
end
end
removed_connections.each do |conn|
conn.disconnect!
end
end Related methods
- Instance methods
- activate
- activated?
- active_connection
- active_connection?
- checkin
- checkout
- clear_reloadable_connections
- clear_reloadable_connections!
- connected?
- connection_descriptor
- connections
- discard!
- discarded?
- disconnect
- disconnect!
- flush
- flush!
- inspect
- internal_metadata
- keep_alive
- lease_connection
- maintainable?
- migration_context
- migrations_paths
- new_connection
- num_available_in_queue
- num_waiting_in_queue
- permanent_lease?
- pin_connection!
- pool_transaction_isolation_level
- pool_transaction_isolation_level=
- preconnect
- prepopulate
- reap
- reaper_lock
- recycle!
- release_connection
- remove
- retire_old_connections
- schedule_query
- schema_cache
- schema_migration
- schema_reflection=
- stat
- unpin_connection!
- with_connection
- with_pool_transaction_isolation_level
- Class methods
- install_executor_hooks
- new
- Private methods
-
acquire_connection -
adopt_connection -
attempt_to_checkout_all_existing_connections -
build_async_executor -
bulk_make_new_connections -
checkout_and_verify -
checkout_for_exclusive_access -
checkout_for_maintenance -
checkout_new_connection -
connection_lease -
name_inspect -
release -
remove_connection_from_thread_cache -
remove_from_maintenance -
return_from_maintenance -
sequential_maintenance -
shard_inspect -
try_to_checkout_new_connection -
try_to_queue_for_background_connection -
with_exclusively_acquired_all_connections -
with_new_connections_blocked