Skip to content

Instantly share code, notes, and snippets.

@j-mcnally
Created September 11, 2014 18:49
Show Gist options
  • Save j-mcnally/558fd5d8d0666b9550fd to your computer and use it in GitHub Desktop.
Save j-mcnally/558fd5d8d0666b9550fd to your computer and use it in GitHub Desktop.
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