Handling timeouts?

Lawrence Pit lawrence.pit at gmail.com
Mon Oct 29 00:07:54 UTC 2012

Hi Aditya

> The default timeout on my Rails app is 30 seconds. The app works fine 
> most of the time but there are some parts of the app which are slow 
> and occasionally totter over the 30 sec response time and timeout. Is 
> there a clean way for me to hook into timeouts and notify myself when 
> timeouts occur? Something like a chance to email myself or send an 
> airbrake notification?

In your unicorn config.rb file, this example would email a snapshot of 
top output when a worker times out:

before_fork do |server, worker|
   `tail -n 5 "#{log_path}/unicorn.log"`.split("\n").each do |line|
     next unless line =~ /SIGKILL.*worker=(\d+)$/
     worker_nr = $1
     next unless worker_nr = worker.nr
     `top -n1 -b | mail -s "#{line}" sysadmin at example.com`

   # …



More information about the mongrel-unicorn mailing list