This commit is contained in:
2026-07-13 17:44:50 +08:00
parent 975fa1ffac
commit 8493f0df03
25 changed files with 1050 additions and 734 deletions
+23 -3
View File
@@ -1,5 +1,6 @@
from celery_app import app
from moldinsight.services.processing_service import processing_service
from shared.config.settings import settings
from shared.utils.logger import get_logger
logger = get_logger(__name__)
@@ -11,11 +12,30 @@ def process_stp_task(self, task_id: str, file_path: str, stp_file_id: int,
"""Celery 任务:异步处理 STP 文件生成模具型腔"""
import asyncio
async def _run():
# Celery 进程不执行 FastAPI startup,必须在此处显式建立连接:
# - redis.asyncio 客户端绑定创建它的循环,而本任务经 asyncio.run 每次新建循环,
# 故每任务需 reconnect();
# - RustFS(Minio) 为同步客户端,不绑定循环,连一次后跨任务复用。
from shared.services.redis_task_manager import redis_task_manager
from moldinsight.storage.rustfs_storage import rustfs_manager
await redis_task_manager.reconnect()
if not rustfs_manager.is_connected:
await rustfs_manager.connect(
endpoint=settings.RUSTFS_ENDPOINT,
access_key=settings.RUSTFS_ACCESS_KEY,
secret_key=settings.RUSTFS_SECRET_KEY,
timeout=settings.RUSTFS_TIMEOUT,
)
await processing_service.process_file_with_storage(
task_id, file_path, stp_file_id, process_params
)
try:
logger.info(f"[celery] 开始处理: {task_id}")
asyncio.run(processing_service.process_file_with_storage(
task_id, file_path, stp_file_id, process_params
))
asyncio.run(_run())
logger.info(f"[celery] 处理完成: {task_id}")
return {"task_id": task_id, "status": "completed"}
except Exception as exc: