From c943606320c6829637dfa8d1f6a3db8a7e40b9a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Pav=C3=A3o?= Date: Fri, 19 Apr 2024 13:53:51 +0200 Subject: [PATCH 1/3] Clean code in celery_config.py --- src/celery_config.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/celery_config.py b/src/celery_config.py index e3b7e141e..09e09aeea 100644 --- a/src/celery_config.py +++ b/src/celery_config.py @@ -15,9 +15,10 @@ Queue('compute-worker', Exchange('compute-worker'), routing_key='compute-worker', queue_arguments={'x-max-priority': 10}), ] -_vhost_apps = {} -# Function to get the app for a vhost + def app_for_vhost(vhost): + # Function to get the app for a vhost + _vhost_apps = {} if vhost not in _vhost_apps: # Take the CELERY_BROKER_URL and replace the vhost with the vhhost for this queue broker_url = settings.CELERY_BROKER_URL @@ -26,7 +27,6 @@ def app_for_vhost(vhost): urllib.parse.uses_relative.append(scheme) urllib.parse.uses_netloc.append(scheme) broker_url = urllib.parse.urljoin(broker_url, vhost) - vhost_app = Celery() # Copy the settings so we can modify the broker url to include the vhost django_settings = copy.copy(settings) @@ -34,5 +34,4 @@ def app_for_vhost(vhost): vhost_app.config_from_object(django_settings, namespace='CELERY') vhost_app.task_queues = app.conf.task_queues _vhost_apps[vhost] = vhost_app - - return _vhost_apps[vhost] \ No newline at end of file + return _vhost_apps[vhost] From b636c187522eafad04e4e1969038585e9a6f4744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Pav=C3=A3o?= Date: Fri, 19 Apr 2024 13:58:05 +0200 Subject: [PATCH 2/3] Update celery_config.py --- src/celery_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/celery_config.py b/src/celery_config.py index 09e09aeea..53b5eadc5 100644 --- a/src/celery_config.py +++ b/src/celery_config.py @@ -15,10 +15,10 @@ Queue('compute-worker', Exchange('compute-worker'), routing_key='compute-worker', queue_arguments={'x-max-priority': 10}), ] +_vhost_apps = {} def app_for_vhost(vhost): # Function to get the app for a vhost - _vhost_apps = {} if vhost not in _vhost_apps: # Take the CELERY_BROKER_URL and replace the vhost with the vhhost for this queue broker_url = settings.CELERY_BROKER_URL From f4737b86fadd8249a5bdf3ccbf0937f8d89fda27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Pav=C3=A3o?= Date: Fri, 19 Apr 2024 14:02:09 +0200 Subject: [PATCH 3/3] Add blank line (flake8) --- src/celery_config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/celery_config.py b/src/celery_config.py index 53b5eadc5..7ef8f818e 100644 --- a/src/celery_config.py +++ b/src/celery_config.py @@ -17,6 +17,7 @@ _vhost_apps = {} + def app_for_vhost(vhost): # Function to get the app for a vhost if vhost not in _vhost_apps: