From 30871bd6cf65eb8607c0075ef74e8e3e8e0e03c8 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Thu, 13 May 2021 11:13:26 -0400 Subject: [PATCH] close db and cache connection in new threads --- awx/main/utils/common.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/awx/main/utils/common.py b/awx/main/utils/common.py index 61c23d06a1..fd9c4d35fa 100644 --- a/awx/main/utils/common.py +++ b/awx/main/utils/common.py @@ -92,6 +92,7 @@ __all__ = [ 'truncate_stdout', 'deepmerge', 'get_event_partition_epoch', + 'cleanup_new_process', ] @@ -1083,3 +1084,17 @@ def create_partition(tblname, start=None, end=None, partition_label=None, minute f'PARTITION OF {tblname} ' f'FOR VALUES FROM (\'{start_timestamp}\') to (\'{end_timestamp}\');' ) + + +def cleanup_new_process(func): + """ + Cleanup django connection, cache connection, before executing new thread or processes entry point, func. + """ + + @wraps(func) + def wrapper_cleanup_new_process(*args, **kwargs): + django_connection.close() + django_cache.close() + return func(*args, **kwargs) + + return wrapper_cleanup_new_process