Skip to content

Instantly share code, notes, and snippets.

@mikeabiezzi
Created June 25, 2012 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeabiezzi/2985827 to your computer and use it in GitHub Desktop.
Save mikeabiezzi/2985827 to your computer and use it in GitHub Desktop.
Patch to Resque interpreting TERM as a soft shutdown.
# Registers the various signal handlers a worker responds to.
#
# TERM: Shutdown immediately, stop processing jobs.
# INT: Shutdown immediately, stop processing jobs.
# QUIT: Shutdown after the current job has finished processing.
# USR1: Kill the forked child immediately, continue processing jobs.
# USR2: Don't process any new jobs
# CONT: Start processing jobs again after a USR2
def register_signal_handlers
trap('TERM') { shutdown! }
trap('INT') { shutdown! }
begin
trap('QUIT') { shutdown }
trap('USR1') { kill_child }
trap('USR2') { pause_processing }
rescue ArgumentError
warn "Signals QUIT, USR1, USR2, and/or CONT not supported."
end
log! "Registered signals"
end
trap('TERM') { shutdown! }
trap('TERM') { shutdown }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment