|
|
@ -323,47 +323,47 @@ class Worker(object):
|
|
|
|
gracefully.
|
|
|
|
gracefully.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def request_force_stop(signum, frame):
|
|
|
|
signal.signal(signal.SIGINT, self.request_stop)
|
|
|
|
"""Terminates the application (cold shutdown).
|
|
|
|
signal.signal(signal.SIGTERM, self.request_stop)
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.log.warning('Cold shut down')
|
|
|
|
def request_force_stop(self, signum, frame):
|
|
|
|
|
|
|
|
"""Terminates the application (cold shutdown).
|
|
|
|
# Take down the horse with the worker
|
|
|
|
"""
|
|
|
|
if self.horse_pid:
|
|
|
|
self.log.warning('Cold shut down')
|
|
|
|
msg = 'Taking down horse {0} with me'.format(self.horse_pid)
|
|
|
|
|
|
|
|
self.log.debug(msg)
|
|
|
|
# Take down the horse with the worker
|
|
|
|
try:
|
|
|
|
if self.horse_pid:
|
|
|
|
os.kill(self.horse_pid, signal.SIGKILL)
|
|
|
|
msg = 'Taking down horse {0} with me'.format(self.horse_pid)
|
|
|
|
except OSError as e:
|
|
|
|
self.log.debug(msg)
|
|
|
|
# ESRCH ("No such process") is fine with us
|
|
|
|
try:
|
|
|
|
if e.errno != errno.ESRCH:
|
|
|
|
os.kill(self.horse_pid, signal.SIGKILL)
|
|
|
|
self.log.debug('Horse already down')
|
|
|
|
except OSError as e:
|
|
|
|
raise
|
|
|
|
# ESRCH ("No such process") is fine with us
|
|
|
|
raise SystemExit()
|
|
|
|
if e.errno != errno.ESRCH:
|
|
|
|
|
|
|
|
self.log.debug('Horse already down')
|
|
|
|
def request_stop(signum, frame):
|
|
|
|
raise
|
|
|
|
"""Stops the current worker loop but waits for child processes to
|
|
|
|
raise SystemExit()
|
|
|
|
end gracefully (warm shutdown).
|
|
|
|
|
|
|
|
"""
|
|
|
|
def request_stop(self, signum, frame):
|
|
|
|
self.log.debug('Got signal {0}'.format(signal_name(signum)))
|
|
|
|
"""Stops the current worker loop but waits for child processes to
|
|
|
|
|
|
|
|
end gracefully (warm shutdown).
|
|
|
|
signal.signal(signal.SIGINT, request_force_stop)
|
|
|
|
"""
|
|
|
|
signal.signal(signal.SIGTERM, request_force_stop)
|
|
|
|
self.log.debug('Got signal {0}'.format(signal_name(signum)))
|
|
|
|
|
|
|
|
|
|
|
|
msg = 'Warm shut down requested'
|
|
|
|
signal.signal(signal.SIGINT, self.request_force_stop)
|
|
|
|
self.log.warning(msg)
|
|
|
|
signal.signal(signal.SIGTERM, self.request_force_stop)
|
|
|
|
|
|
|
|
|
|
|
|
# If shutdown is requested in the middle of a job, wait until
|
|
|
|
msg = 'Warm shut down requested'
|
|
|
|
# finish before shutting down
|
|
|
|
self.log.warning(msg)
|
|
|
|
if self.get_state() == 'busy':
|
|
|
|
|
|
|
|
self._stop_requested = True
|
|
|
|
# If shutdown is requested in the middle of a job, wait until
|
|
|
|
self.log.debug('Stopping after current horse is finished. '
|
|
|
|
# finish before shutting down
|
|
|
|
'Press Ctrl+C again for a cold shutdown.')
|
|
|
|
if self.get_state() == 'busy':
|
|
|
|
else:
|
|
|
|
self._stop_requested = True
|
|
|
|
raise StopRequested()
|
|
|
|
self.log.debug('Stopping after current horse is finished. '
|
|
|
|
|
|
|
|
'Press Ctrl+C again for a cold shutdown.')
|
|
|
|
signal.signal(signal.SIGINT, request_stop)
|
|
|
|
else:
|
|
|
|
signal.signal(signal.SIGTERM, request_stop)
|
|
|
|
raise StopRequested()
|
|
|
|
|
|
|
|
|
|
|
|
def check_for_suspension(self, burst):
|
|
|
|
def check_for_suspension(self, burst):
|
|
|
|
"""Check to see if workers have been suspended by `rq suspend`"""
|
|
|
|
"""Check to see if workers have been suspended by `rq suspend`"""
|
|
|
|