增加celery任务队列,任务持久化(服务重启不丢)、支持多 Worker 水平扩展、失败自动重试

This commit is contained in:
2026-05-28 17:59:39 +08:00
parent 6ad22e4466
commit 44902207c9
9 changed files with 133 additions and 47 deletions
+27
View File
@@ -0,0 +1,27 @@
from celery_app import app
from services.processing_service import processing_service
from utils.logger import get_logger
logger = get_logger(__name__)
@app.task(bind=True, max_retries=1, default_retry_delay=60)
def process_stp_task(self, task_id: str, file_path: str, stp_file_id: int,
process_params: dict):
"""Celery 任务:异步处理 STP 文件生成模具型腔"""
import asyncio
try:
logger.info(f"[celery] 开始处理: {task_id}")
asyncio.run(processing_service.process_file_with_storage(
task_id, file_path, stp_file_id, process_params
))
logger.info(f"[celery] 处理完成: {task_id}")
return {"task_id": task_id, "status": "completed"}
except Exception as exc:
logger.error(f"[celery] 处理失败: {task_id}, error={exc}")
try:
self.retry(exc=exc)
except Exception:
pass
raise