Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 32 lines (27 sloc) 0.836 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
# This will ride alongside god and kill any rogue stale worker
# processes. Their sacrifice is for the greater good.

WORKER_TIMEOUT = 60 * 10 # 10 minutes
STALE_EXEMPTIONS = ["imports"]

Thread.new do
  loop do
    begin
      lines = `ps -e -o pid,command | grep [r]esque`.split("\n")
      lines.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
          parent = lines.detect { |line| line.split(" ").first == parts[3] }
          queue = parent.split(" ")[3]
          next if STALE_EXEMPTIONS.include?(queue)
          ::Process.kill('USR1', parts[0].to_i)
        end
      end
    rescue
      # don't die because of stupid exceptions
      nil
    end

    sleep 30
  end
end
Something went wrong with that request. Please try again.