Skip to content

Instantly share code, notes, and snippets.

@nevinera
Created December 9, 2011 13:29
Show Gist options
  • Select an option

  • Save nevinera/1451524 to your computer and use it in GitHub Desktop.

Select an option

Save nevinera/1451524 to your computer and use it in GitHub Desktop.
monkey patch on delayed_job 2.1.4 to propagate sigquit exceptions into application code
module Delayed
class Worker
def start
say "Starting job worker"
trap('TERM') { $exit = true; raise SignalException.new("TERM")}
trap('INT') { say 'Exiting...'; $exit = true }
loop do
result = nil
realtime = Benchmark.realtime do
result = work_off
end
count = result.sum
break if $exit
if count.zero?
sleep(self.class.sleep_delay)
else
say "#{count} jobs processed at %.4f j/s, %d failed ..." % [count / realtime, result.last]
end
break if $exit
end
ensure
Delayed::Job.clear_locks!(name)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment