From 3af35dbad6bde6f48a91583b75be725ba1d18445 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Wed, 28 Aug 2024 16:18:53 -0400 Subject: [PATCH] Consistent behavior with dispatcher and callback --- awx/main/management/commands/run_callback_receiver.py | 9 +++++---- awx/main/management/commands/run_dispatcher.py | 9 +++++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/awx/main/management/commands/run_callback_receiver.py b/awx/main/management/commands/run_callback_receiver.py index 624a34cd2888..8f67909dadcb 100644 --- a/awx/main/management/commands/run_callback_receiver.py +++ b/awx/main/management/commands/run_callback_receiver.py @@ -1,10 +1,11 @@ # Copyright (c) 2015 Ansible, Inc. # All Rights Reserved. +import redis + from django.conf import settings from django.core.management.base import BaseCommand, CommandError - -from redis.exceptions import ConnectionError +import redis.exceptions from awx.main.analytics.subsystem_metrics import CallbackReceiverMetricsServer from awx.main.dispatch.control import Control @@ -31,8 +32,8 @@ def handle(self, *arg, **options): try: CallbackReceiverMetricsServer().start() - except ConnectionError as exc: - raise CommandError(f'Could not connect to redis, error:\n{exc}\n') + except redis.exceptions.ConnectionError as exc: + raise CommandError(f'Callback receiver could not connect to redis, error: {exc}') try: consumer = AWXConsumerRedis( diff --git a/awx/main/management/commands/run_dispatcher.py b/awx/main/management/commands/run_dispatcher.py index 28d954abffcd..f1eab29b1fc0 100644 --- a/awx/main/management/commands/run_dispatcher.py +++ b/awx/main/management/commands/run_dispatcher.py @@ -3,8 +3,10 @@ import logging import yaml +import redis + from django.conf import settings -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandError from awx.main.dispatch import get_task_queuename from awx.main.dispatch.control import Control @@ -63,7 +65,10 @@ def handle(self, *arg, **options): consumer = None - DispatcherMetricsServer().start() + try: + DispatcherMetricsServer().start() + except redis.exceptions.ConnectionError as exc: + raise CommandError(f'Dispatcher could not connect to redis, error: {exc}') try: queues = ['tower_broadcast_all', 'tower_settings_change', get_task_queuename()]