From f75df33c4216a2981d0de93b53255c7a427969a0 Mon Sep 17 00:00:00 2001 From: Prajna1999 Date: Fri, 20 Mar 2026 18:26:42 +0530 Subject: [PATCH 1/2] fix: import celery issues --- backend/app/celery/celery_app.py | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/backend/app/celery/celery_app.py b/backend/app/celery/celery_app.py index 81fba8cb2..5fe208512 100644 --- a/backend/app/celery/celery_app.py +++ b/backend/app/celery/celery_app.py @@ -1,8 +1,43 @@ +import importlib +import logging + from celery import Celery +from celery.signals import worker_process_init from kombu import Exchange, Queue from app.core.config import settings +logger = logging.getLogger(__name__) + +# All modules referenced as function_path in execute_high/low_priority_task calls. +# Pre-importing these at worker process startup eliminates the 2-5s cold-import +# penalty on the first task execution. +_JOB_MODULES = [ + "app.services.llm.jobs", + "app.services.response.jobs", + "app.services.doctransform.job", + "app.services.collections.create_collection", + "app.services.collections.delete_collection", + "app.services.stt_evaluations.batch_job", + "app.services.tts_evaluations.batch_job", + "app.services.tts_evaluations.batch_result_processing", + "app.services.stt_evaluations.metric_job", +] + + +@worker_process_init.connect +def warmup_job_modules(sender, **kwargs: object) -> None: + """Pre-import all job modules so the first task execution is not delayed by cold imports.""" + for module_path in _JOB_MODULES: + try: + importlib.import_module(module_path) + logger.info(f"[warmup_job_modules] Pre-imported {module_path}") + except Exception as exc: + logger.warning( + f"[warmup_job_modules] Failed to pre-import {module_path}: {exc}" + ) + + # Create Celery instance celery_app = Celery( "ai_platform", From 3c8dd9822b5bb7c31b39bad0e0ce0b62da6b2395 Mon Sep 17 00:00:00 2001 From: Prajna1999 Date: Fri, 20 Mar 2026 18:32:36 +0530 Subject: [PATCH 2/2] chore: logger debug --- backend/app/celery/celery_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/app/celery/celery_app.py b/backend/app/celery/celery_app.py index 5fe208512..5335d19d5 100644 --- a/backend/app/celery/celery_app.py +++ b/backend/app/celery/celery_app.py @@ -31,7 +31,7 @@ def warmup_job_modules(sender, **kwargs: object) -> None: for module_path in _JOB_MODULES: try: importlib.import_module(module_path) - logger.info(f"[warmup_job_modules] Pre-imported {module_path}") + logger.debug(f"[warmup_job_modules] Pre-imported {module_path}") except Exception as exc: logger.warning( f"[warmup_job_modules] Failed to pre-import {module_path}: {exc}"