From 9303d344c099031ac153cde3d6d1e1256ea18d51 Mon Sep 17 00:00:00 2001
From: Timothe Jost <timothe.jost@wanadoo.fr>
Date: Thu, 4 Apr 2024 21:25:19 +0200
Subject: [PATCH] little change to revert the ability to run create_celery_app
 without raising exceptions if it fails

---
 src/pypelines/__init__.py     |  2 +-
 src/pypelines/celery_tasks.py | 32 +++++++++++++++++++-------------
 2 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/pypelines/__init__.py b/src/pypelines/__init__.py
index 2f181b6..a1932b5 100644
--- a/src/pypelines/__init__.py
+++ b/src/pypelines/__init__.py
@@ -1,4 +1,4 @@
-__version__ = "0.0.48"
+__version__ = "0.0.49"
 
 from . import loggs
 from .pipes import *
diff --git a/src/pypelines/celery_tasks.py b/src/pypelines/celery_tasks.py
index 4c2301b..2ee1cce 100644
--- a/src/pypelines/celery_tasks.py
+++ b/src/pypelines/celery_tasks.py
@@ -316,8 +316,26 @@ class LogTask:
 
 
 def create_celery_app(conf_path, app_name="pypelines", v_host=None) -> "Celery | None":
+
+    failure_message = (
+        f"Celery app : {app_name} failed to be created."
+        "Don't worry, about this alert, "
+        "this is not be an issue if you didn't explicitely planned on using celery. Issue was : "
+    )
+
+    logger = getLogger("pypelines.create_celery_app")
+
+    if app_name in APPLICATIONS_STORE.keys():
+        logger.warning(f"Tried to create a celery app named {app_name}, but it already exists. Returning it instead.")
+        return APPLICATIONS_STORE[app_name]
+
+    try:
+        from celery import Task
+    except ImportError as e:
+        logger.warning(f"{failure_message} Could not import celery app. {e}")
+        return None
+
     from types import MethodType
-    from celery import Task
 
     def get_setting_files_path(conf_path) -> List[Path]:
         conf_path = Path(conf_path)
@@ -480,18 +498,6 @@ def create_celery_app(conf_path, app_name="pypelines", v_host=None) -> "Celery |
         )
         return task_record
 
-    failure_message = (
-        f"Celery app : {app_name} failed to be created."
-        "Don't worry, about this alert, "
-        "this is not be an issue if you didn't explicitely planned on using celery. Issue was : "
-    )
-
-    logger = getLogger("pypelines.create_celery_app")
-
-    if app_name in APPLICATIONS_STORE.keys():
-        logger.warning(f"Tried to create a celery app named {app_name}, but it already exists. Returning it instead.")
-        return APPLICATIONS_STORE[app_name]
-
     settings_files = get_setting_files_path(conf_path)
 
     if len(settings_files) == 0:
-- 
GitLab