mirror of
https://github.com/ansible/awx.git
synced 2026-04-14 06:29:25 -02:30
graceful killing of receiver worker processes
This commit is contained in:
@@ -27,6 +27,17 @@ from awx.main.models import * # noqa
|
|||||||
logger = logging.getLogger('awx.main.commands.run_callback_receiver')
|
logger = logging.getLogger('awx.main.commands.run_callback_receiver')
|
||||||
|
|
||||||
|
|
||||||
|
class WorkerSignalHandler:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self.kill_now = False
|
||||||
|
signal.signal(signal.SIGINT, self.exit_gracefully)
|
||||||
|
signal.signal(signal.SIGTERM, self.exit_gracefully)
|
||||||
|
|
||||||
|
def exit_gracefully(self, *args, **kwargs):
|
||||||
|
self.kill_now = True
|
||||||
|
|
||||||
|
|
||||||
class CallbackBrokerWorker(ConsumerMixin):
|
class CallbackBrokerWorker(ConsumerMixin):
|
||||||
def __init__(self, connection, use_workers=True):
|
def __init__(self, connection, use_workers=True):
|
||||||
self.connection = connection
|
self.connection = connection
|
||||||
@@ -102,13 +113,14 @@ class CallbackBrokerWorker(ConsumerMixin):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def callback_worker(self, queue_actual, idx):
|
def callback_worker(self, queue_actual, idx):
|
||||||
while True:
|
signal_handler = WorkerSignalHandler()
|
||||||
|
while not signal_handler.kill_now:
|
||||||
try:
|
try:
|
||||||
body = queue_actual.get(block=True, timeout=1)
|
body = queue_actual.get(block=True, timeout=1)
|
||||||
except QueueEmpty:
|
except QueueEmpty:
|
||||||
continue
|
continue
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info("Exception on worker thread, restarting: " + str(e))
|
logger.error("Exception on worker thread, restarting: " + str(e))
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
if 'job_id' not in body and 'ad_hoc_command_id' not in body:
|
if 'job_id' not in body and 'ad_hoc_command_id' not in body:
|
||||||
|
|||||||
Reference in New Issue
Block a user