Skip to content

Instantly share code, notes, and snippets.

@kml
Created December 13, 2016 23:05
Show Gist options
  • Save kml/1c9483cf537d8852258549a5f97f7d81 to your computer and use it in GitHub Desktop.
Save kml/1c9483cf537d8852258549a5f97f7d81 to your computer and use it in GitHub Desktop.
# encoding: utf-8
# config/initializers/active_record_disconnect.rb
# Disconnect after intialization.
# Helpful for TorqueBox keeping connection for each
# runtime even when it is not used.
#
# $ rails c
# [1] > ActiveRecord::Base.connection_pool.connections.size
# => 0
# [2] > ActiveRecord::Base.connection.tables
# => ["schema_migrations", "users"]
# [3] > ActiveRecord::Base.connection_pool.connections.size
# => 1
ActiveSupport.on_load(:after_initialize) do
begin
ActiveRecord::Base.connection_pool.disconnect!
rescue ActiveRecord::ConnectionNotEstablished
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment