Created
September 11, 2014 18:49
-
-
Save j-mcnally/558fd5d8d0666b9550fd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
WORKER_TIMEOUT = 60 * 10 # 10 minutes | |
loop do | |
begin | |
begin | |
puts "Checking proccesses" | |
`ps -e -o pid,command | grep 'resque.*Forked'`.split("\n").each do |line| | |
parts = line.split(' ') | |
next if parts[-2] != "at" | |
started = parts[-1].to_i | |
elapsed = Time.now - Time.at(started) | |
if elapsed >= WORKER_TIMEOUT | |
::Process.kill('USR1', parts[0].to_i) | |
end | |
end | |
rescue Exception => e | |
raise e | |
end | |
sleep 60 | |
rescue SystemExit, Interrupt | |
puts "Will now quit" | |
break | |
rescue | |
nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment