Middleware for timing out current unicorn worker if request takes to long time.
If a request times out, a handler block will be called and the current worker process will be killed (using SIGTERM).
The gem is tested using Ruby 1.9.3p194.
Add this line to your application's Gemfile:
gem 'unicorn-timeout'
And then execute:
$ bundle
Or install it yourself as:
$ gem install unicorn-timeout
In config/application.rb
:
config.middleware.use Unicorn::Timeout
In config/initializer/unicorn-timeout.rb
(optional):
# Timeout in seconds
Unicorn::Timeout.timeout = 15 # default
# Block that will run (within Thread.exclusive, on monitor thread) just before sending signal to process
Unicorn::Timeout.handler = lambda { |backtrace| STDERR.puts("Unicorn::Timeout is killing worker ##{Process.pid} with backtrace:\n#{backtrace.inspect}") } # default
# Signal that will be sent to current process if timeout is reached
Unicorn::Timeout.signal = "TERM" # default
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Added some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
This work was inspired and influenced by rack-timeout.