Created
December 13, 2016 23:05
-
-
Save kml/1c9483cf537d8852258549a5f97f7d81 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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