From af3604b438856ab41a7414dcb3749e06a1b1760d Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Fri, 8 Jul 2022 13:46:54 -0400 Subject: [PATCH] Avoid other cases of throwing error due to unregistered isntance --- awx/main/analytics/subsystem_metrics.py | 6 +++++- awx/main/dispatch/reaper.py | 6 +++++- awx/main/management/commands/run_dispatcher.py | 3 +-- awx/main/tasks/system.py | 1 + 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/awx/main/analytics/subsystem_metrics.py b/awx/main/analytics/subsystem_metrics.py index 1b5e3d1cc4ac..b0fd81172bd0 100644 --- a/awx/main/analytics/subsystem_metrics.py +++ b/awx/main/analytics/subsystem_metrics.py @@ -166,7 +166,11 @@ def __init__(self, auto_pipe_execute=False, instance_name=None): elif settings.IS_TESTING(): self.instance_name = "awx_testing" else: - self.instance_name = Instance.objects.me().hostname + try: + self.instance_name = Instance.objects.me().hostname + except Exception as e: + self.instance_name = settings.CLUSTER_HOST_ID + logger.info(f'Instance {self.instance_name} seems to be unregistered, error: {e}') # metric name, help_text METRICSLIST = [ diff --git a/awx/main/dispatch/reaper.py b/awx/main/dispatch/reaper.py index a86664b80c2f..ba752f4fe652 100644 --- a/awx/main/dispatch/reaper.py +++ b/awx/main/dispatch/reaper.py @@ -15,7 +15,11 @@ def startup_reaping(): If this particular instance is starting, then we know that any running jobs are invalid so we will reap those jobs as a special action here """ - me = Instance.objects.me() + try: + me = Instance.objects.me() + except RuntimeError as e: + logger.warning(f'Local instance is not registered, not running startup reaper: {e}') + return jobs = UnifiedJob.objects.filter(status='running', controller_node=me.hostname) job_ids = [] for j in jobs: diff --git a/awx/main/management/commands/run_dispatcher.py b/awx/main/management/commands/run_dispatcher.py index e4d17f2aed9e..2fc35a75d280 100644 --- a/awx/main/management/commands/run_dispatcher.py +++ b/awx/main/management/commands/run_dispatcher.py @@ -7,7 +7,7 @@ from django.core.management.base import BaseCommand from django.db import connection as django_connection -from awx.main.dispatch import get_local_queuename, reaper +from awx.main.dispatch import get_local_queuename from awx.main.dispatch.control import Control from awx.main.dispatch.pool import AutoscalePool from awx.main.dispatch.worker import AWXConsumerPG, TaskWorker @@ -53,7 +53,6 @@ def handle(self, *arg, **options): # (like the node heartbeat) periodic.run_continuously() - reaper.startup_reaping() consumer = None try: diff --git a/awx/main/tasks/system.py b/awx/main/tasks/system.py index d8d307a2d9f3..2c8daa8310c7 100644 --- a/awx/main/tasks/system.py +++ b/awx/main/tasks/system.py @@ -103,6 +103,7 @@ def dispatch_startup(): # apply_cluster_membership_policies() cluster_node_heartbeat() + reaper.startup_reaping() m = Metrics() m.reset_values()