Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions backend/app/celery/celery_app.py
Original file line number Diff line number Diff line change
@@ -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:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Type-annotate and underscore unused signal params

Line [29] leaves sender untyped and keeps two intentionally-unused args as regular names. Please type sender and prefix both unused params with _ to satisfy lint and readability.

Proposed fix
-@worker_process_init.connect
-def warmup_job_modules(sender, **kwargs: object) -> None:
+@worker_process_init.connect
+def warmup_job_modules(_sender: object, **_kwargs: object) -> None:

As per coding guidelines, "**/*.py: Always add type hints to all function parameters and return values in Python code" and "Use Python 3.11+ with type hints throughout the codebase".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def warmup_job_modules(sender, **kwargs: object) -> None:
`@worker_process_init.connect`
def warmup_job_modules(_sender: object, **_kwargs: object) -> None:
🧰 Tools
🪛 Ruff (0.15.6)

[warning] 29-29: Unused function argument: sender

(ARG001)


[warning] 29-29: Unused function argument: kwargs

(ARG001)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/app/celery/celery_app.py` at line 29, The function warmup_job_modules
should type and mark unused signal parameters as intentionally unused: change
the signature to accept a typed sender parameter (e.g., _sender: Any) and a
folded kwargs parameter named with a leading underscore (e.g., **_kwargs: Any)
while keeping the return type None; update any imports to include Any from
typing if necessary and leave the function body unchanged.

"""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.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}"
)


# Create Celery instance
celery_app = Celery(
"ai_platform",
Expand Down
Loading