Created
August 8, 2012 12:01
-
-
Save romanbsd/3294589 to your computer and use it in GitHub Desktop.
rack timeout
This file contains 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 '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