Skip to content

Instantly share code, notes, and snippets.

@qerub
Last active October 11, 2015 03:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save qerub/3793354 to your computer and use it in GitHub Desktop.
Save qerub/3793354 to your computer and use it in GitHub Desktop.
Rack middleware that makes sure requests don't get a dead Sequel connection
require "sequel/extensions/connection_validator"
# https://github.com/jeremyevans/sequel/blob/master/lib/sequel/extensions/connection_validator.rb
module Rack
class SequelConnectionValidator
def initialize(app, db)
@app = app
@db = db
@db.extension(:connection_validator)
@db.pool.connection_validation_timeout = -1
end
def call(env)
@db.synchronize do
@app.call(env)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment