Created
February 14, 2013 14:26
-
-
Save mindscratch/4953139 to your computer and use it in GitHub Desktop.
Rack middleware to close Mongoid's connections to MongoDB. See https://github.com/mongoid/mongoid/issues/2369.
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
| require 'mongoid' | |
| class MongoidCloseConnections | |
| def initialize(app) | |
| @app = app | |
| end | |
| def call(env) | |
| path = env['PATH_INFO'] || '' | |
| begin | |
| @app.call env | |
| ensure | |
| unless path.start_with?('/assets/') | |
| Mongoid.default_session.disconnect | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment