Created
December 9, 2011 13:29
-
-
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
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
| 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