0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Middleware for timing out current unicorn worker if request takes to long time.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.3
>= 0
 Project Readme

Unicorn::Timeout

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).

Compatibility

The gem is tested using Ruby 1.9.3p194.

Installation

Add this line to your application's Gemfile:

gem 'unicorn-timeout'

And then execute:

$ bundle

Or install it yourself as:

$ gem install unicorn-timeout

Setup/Usage (Rails 3)

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

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Credit

This work was inspired and influenced by rack-timeout.