From a5163259ece9361ccc58f2bd86e15a5767a7f7fb Mon Sep 17 00:00:00 2001 From: David O Neill Date: Wed, 21 Feb 2024 18:44:31 +0000 Subject: [PATCH] English string validation to error code validation --- awx/main/tasks/system.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/awx/main/tasks/system.py b/awx/main/tasks/system.py index 4ebe1d576612..d4a34f0abd39 100644 --- a/awx/main/tasks/system.py +++ b/awx/main/tasks/system.py @@ -6,6 +6,7 @@ import json import logging import os +import psycopg from io import StringIO from contextlib import redirect_stdout import shutil @@ -630,10 +631,17 @@ def cluster_node_heartbeat(dispatch_time=None, worker_tasks=None): logger.error("Host {} last checked in at {}, marked as lost.".format(other_inst.hostname, other_inst.last_seen)) except DatabaseError as e: - if 'did not affect any rows' in str(e): - logger.debug('Another instance has marked {} as lost'.format(other_inst.hostname)) + if hasattr(e, 'sqlstate'): + sqlstate = e.sqlstate + sqlstate_str = psycopg.errors.lookup(sqlstate) + logger.debug('SQL Error state: {} - {}'.format(sqlstate, sqlstate_str)) + + if sqlstate == psycopg.errors.NoData: + logger.debug('Another instance has marked {} as lost'.format(other_inst.hostname)) + else: + logger.exception("Error marking {} as lost.".format(other_inst.hostname)) else: - logger.exception('Error marking {} as lost'.format(other_inst.hostname)) + logger.exception('No SQL state available. Error marking {} as lost'.format(other_inst.hostname)) # Run local reaper if worker_tasks is not None: