From da004da68a11a910ade1da880a614f3019474862 Mon Sep 17 00:00:00 2001 From: jessicamack Date: Thu, 9 Feb 2023 16:18:43 -0500 Subject: [PATCH] make reconfigure_rsyslog a task Signed-off-by: jessicamack --- awx/conf/views.py | 6 +++--- awx/main/management/commands/run_rsyslog_configurer.py | 5 ++++- awx/main/utils/external_logging.py | 2 ++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/awx/conf/views.py b/awx/conf/views.py index e4a8375122..f12075148b 100644 --- a/awx/conf/views.py +++ b/awx/conf/views.py @@ -30,7 +30,7 @@ from awx.main.tasks.system import clear_setting_cache from awx.conf.models import Setting from awx.conf.serializers import SettingCategorySerializer, SettingSingletonSerializer from awx.conf import settings_registry -from awx.main.utils.external_logging import send_pg_notify +from awx.main.utils.external_logging import reconfigure_rsyslog SettingCategory = collections.namedtuple('SettingCategory', ('url', 'slug', 'name')) @@ -122,7 +122,7 @@ class SettingSingletonDetail(RetrieveUpdateDestroyAPIView): connection.on_commit(lambda: clear_setting_cache.delay(settings_change_list)) if any([setting.startswith('LOG_AGGREGATOR') for setting in settings_change_list]): # call notify to rsyslog. no data is need so payload is empty - send_pg_notify('rsyslog_configurer', "") + reconfigure_rsyslog.delay() def destroy(self, request, *args, **kwargs): instance = self.get_object() @@ -140,7 +140,7 @@ class SettingSingletonDetail(RetrieveUpdateDestroyAPIView): connection.on_commit(lambda: clear_setting_cache.delay(settings_change_list)) if any([setting.startswith('LOG_AGGREGATOR') for setting in settings_change_list]): # call notify to rsyslog. no data is need so payload is empty - send_pg_notify('rsyslog_configurer', "") + reconfigure_rsyslog.delay() # When TOWER_URL_BASE is deleted from the API, reset it to the hostname # used to make the request as a default. diff --git a/awx/main/management/commands/run_rsyslog_configurer.py b/awx/main/management/commands/run_rsyslog_configurer.py index 5cc214ced9..61e7aa14a6 100644 --- a/awx/main/management/commands/run_rsyslog_configurer.py +++ b/awx/main/management/commands/run_rsyslog_configurer.py @@ -1,9 +1,11 @@ import logging +import json from django.core.management.base import BaseCommand from django.conf import settings from django.core.cache import cache from awx.main.dispatch import pg_bus_conn +from awx.main.dispatch.worker.task import TaskWorker from awx.main.utils.external_logging import reconfigure_rsyslog logger = logging.getLogger('awx.main.rsyslog_configurer') @@ -31,7 +33,8 @@ class Command(BaseCommand): setting_keys = [k for k in dir(settings) if k.startswith('LOG_AGGREGATOR')] cache.delete_many(setting_keys) settings._awx_conf_memoizedcache.clear() - reconfigure_rsyslog() + body = json.loads(e.payload) + TaskWorker.run_callable(body) except Exception: # Log unanticipated exception in addition to writing to stderr to get timestamps and other metadata logger.exception('Encountered unhandled error in rsyslog_configurer main loop') diff --git a/awx/main/utils/external_logging.py b/awx/main/utils/external_logging.py index e3e0a3d1c8..635887ec14 100644 --- a/awx/main/utils/external_logging.py +++ b/awx/main/utils/external_logging.py @@ -6,6 +6,7 @@ import urllib.parse as urlparse from django.conf import settings from awx.main.utils.reload import supervisor_service_command +from awx.main.dispatch.publish import task from awx.main.dispatch import pg_bus_conn @@ -115,6 +116,7 @@ def construct_rsyslog_conf_template(settings=settings): return tmpl +@task(queue='rsyslog_configurer') def reconfigure_rsyslog(): tmpl = construct_rsyslog_conf_template() # Write config to a temp file then move it to preserve atomicity