From aa9ac0463be6fa1aa480d021c05b3833df576288 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Tue, 17 Sep 2024 13:13:26 +0100 Subject: [PATCH] Try with global variable --- lib/galaxy/celery/__init__.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/galaxy/celery/__init__.py b/lib/galaxy/celery/__init__.py index dd9f26acd91f..5db799e149eb 100644 --- a/lib/galaxy/celery/__init__.py +++ b/lib/galaxy/celery/__init__.py @@ -10,6 +10,7 @@ Any, Callable, Dict, + Optional, ) import pebble @@ -201,20 +202,26 @@ def wrapper(*args, **kwds): return decorate -@lru_cache(maxsize=1) +_celery_app: Optional[GalaxyCelery] = None + + def get_celery_app() -> GalaxyCelery: - celery_app = GalaxyCelery( + global _celery_app + + if _celery_app is not None: + return _celery_app + _celery_app = GalaxyCelery( "galaxy", include=TASKS_MODULES, task_default_queue=DEFAULT_TASK_QUEUE, task_create_missing_queues=True, timezone="UTC", ) - celery_app.set_default() + _celery_app.set_default() config = get_config() - config_celery_app(config, celery_app) - setup_periodic_tasks(config, celery_app) - return celery_app + config_celery_app(config, _celery_app) + setup_periodic_tasks(config, _celery_app) + return _celery_app def config_celery_app(config, celery_app):