Skip to content

Instantly share code, notes, and snippets.

@romanbsd
Created August 8, 2012 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romanbsd/3294589 to your computer and use it in GitHub Desktop.
Save romanbsd/3294589 to your computer and use it in GitHub Desktop.
rack timeout
require 'timeout'
module Rack
class Timeout
def initialize(app, timeout = 5)
@app, @timeout = app, timeout
end
def call(env)
::Timeout.timeout(@timeout, ::Timeout::Error) { @app.call(env) }
rescue ::Timeout::Error
[504, {'Content-Type' => 'text/plain'}, ['Gateway Timeout']]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment