Skip to content

Abort requests that are taking too long, now with path filtering

License

Notifications You must be signed in to change notification settings

cqsdev/rack-timeout

 
 

Repository files navigation

Rack::Timeout::Select

A fork of Rack::Timeout with extended functionality that allows filtering timeout by Rails request routes. Default behaviour is still preserved, for documentation on original middleware see the link above.

Basic Usage

Pass an an array of paths strings you want to exclude from or only run timeout for.

Rails apps, manually

# Gemfile
gem "rack-timeout", require:"rack/timeout/base", :git => 'git://github.com/cqsdev/rack-timeout.git'
# config/initializers/rack_timeout.rb

# insert middleware wherever you want in the stack, optionally pass
# initialization arguments, or use environment variables
Rails.application.config.middleware.insert_before Rack::Runtime, Rack::Timeout::Select, service_timeout: 5, exclude: ["statistics"]

Or include the original Rack::Timeout instead, if you want to temporary disable path filtering.

Configuring

Same as the original Rack::Timeout, it takes the following settings, shown here with their default values and associated environment variables.

service_timeout:   15     # RACK_TIMEOUT_SERVICE_TIMEOUT
wait_timeout:      30     # RACK_TIMEOUT_WAIT_TIMEOUT
wait_overtime:     60     # RACK_TIMEOUT_WAIT_OVERTIME
service_past_wait: false  # RACK_TIMEOUT_SERVICE_PAST_WAIT
term_on_timeout:   false  # RACK_TIMEOUT_TERM_ON_TIMEOUT
exclude:           []     # RACK_TIMEOUT_EXCLUDE
only:              []     # RACK_TIMEOUT_ONLY

Both exclude and only can be used at the same time, in this case excluded paths will be substracted from the only array.

These settings can be overridden during middleware initialization or environment variables RACK_TIMEOUT_* mentioned above. Middleware parameters take precedence:

use Rack::Timeout::Select, service_timeout: 5, exclude: ["api"]

Demo application

For more on these settings, please see doc/settings.

Further Documentation

Please see the doc folder for further documentation on:

Additionally there is a demo app that shows the impact of changing settings and how the library behaves when a timeout is hit.

Contributing

Run the test suite:

bundle
bundle exec rake test

Compatibility

This version of Rack::Timeout is compatible with Ruby 2.3 and up, and, for Rails apps, Rails 3.x and up.


Copyright © 2010-2020 Caio Chassot, released under the MIT license http://github.com/zombocom/rack-timeout

About

Abort requests that are taking too long, now with path filtering

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%