#345: fixed: could not obtain a database connection within 5.000 seconds

This commit is contained in:
Vokhmin Alexey V 2014-03-26 00:25:36 +04:00
parent c87c150bcd
commit 3eda2718f8
2 changed files with 17 additions and 0 deletions

View File

@ -14,6 +14,11 @@ module Rosa
class Application < Rails::Application class Application < Rails::Application
config.i18n.enforce_available_locales = true config.i18n.enforce_available_locales = true
unless Rails.env.test?
require 'close_ar_connections_middleware'
config.middleware.insert_after('Rack::Sendfile', CloseArConnectionsMiddleware)
end
# Rate limit # Rate limit
config.middleware.insert_before Rack::Runtime, ApiDefender config.middleware.insert_before Rack::Runtime, ApiDefender

View File

@ -0,0 +1,12 @@
# "Coffee's for closers"
class CloseArConnectionsMiddleware
def initialize(app)
@app = app
end
def call(env)
@app.call(env)
ensure
ActiveRecord::Base.clear_active_connections! unless env.key?('rack.test')
end
end