Files
meida_backend/apps/worker/celery_app.py
T
xsl 746b66da01 feat(api): vertical slice POST /v1/agent/chat and the Celery ping path
One request exercises every layer: JWT auth, quota reservation, a versioned
prompt through the LLM gateway, a cost row, quota commit or refund, and the
unified envelope. The trivial ping task proves the queue routing and the
tk_task transitions before any real long-running task is written.

Routes are mounted at the /api/v1 base path of 架构文档 §9.1; /v1/* is
rewritten to it at the ASGI layer so both spellings work from one route table.
2026-08-14 00:26:39 +08:00

55 lines
1.5 KiB
Python
Executable File

"""Celery application with the four queues from TD-11 / 架构文档 §3.1.
gpu 换装、发型、抠图 —— 并发上限由 GPU 容量决定,队列即容量 (§7.3)
cpu 报告视觉分析、渲染
io 外部 API 调用、推送、上传
beat 定时任务(单实例,防重)
Queue isolation is the point: 换装排队不能把报告生成拖慢。
"""
from __future__ import annotations
from celery import Celery
from kombu import Queue
from packages.shared.config import get_settings
from packages.shared.logging import configure_logging
settings = get_settings()
configure_logging(
level=settings.log_level,
json_output=settings.log_json,
extra_redact_keys=settings.extra_redact_keys,
)
celery_app = Celery(
"meida",
broker=settings.celery_broker_url,
backend=settings.celery_result_backend,
include=["apps.worker.tasks"],
)
celery_app.conf.update(
task_default_queue="cpu",
task_queues=(
Queue("gpu"),
Queue("cpu"),
Queue("io"),
Queue("beat"),
),
task_routes={
"meida.tryon.*": {"queue": "gpu"},
"meida.matting.*": {"queue": "gpu"},
"meida.report.*": {"queue": "cpu"},
"meida.notify.*": {"queue": "io"},
},
task_acks_late=True,
task_reject_on_worker_lost=True,
task_track_started=True,
worker_prefetch_multiplier=1,
broker_connection_retry_on_startup=True,
timezone="Asia/Shanghai",
result_expires=86400,
)