make reconfigure_rsyslog a task

Signed-off-by: jessicamack <jmack@redhat.com>
This commit is contained in:
jessicamack 2023-02-09 16:18:43 -05:00 committed by Hao Liu
parent b29f2f88d0
commit da004da68a
3 changed files with 9 additions and 4 deletions

View File

@ -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.

View File

@ -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')

View File

@ -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