优化
This commit is contained in:
@@ -28,23 +28,28 @@ _background_tasks: set = set()
|
||||
_dispatch_semaphore = asyncio.Semaphore(2)
|
||||
|
||||
|
||||
async def _run_with_limit(task_id: str, file_path: str, stp_file_id: int, process_params: dict):
|
||||
async def _run_with_limit(task_id: str, stp_file_id: int, process_params: dict):
|
||||
async with _dispatch_semaphore:
|
||||
from moldinsight.services.processing_service import processing_service
|
||||
await processing_service.process_file_with_storage(
|
||||
task_id, file_path, stp_file_id, process_params
|
||||
task_id, stp_file_id, process_params
|
||||
)
|
||||
|
||||
|
||||
def dispatch_processing(task_id: str, file_path: str, stp_file_id: int, process_params: dict):
|
||||
"""调度 STP 处理任务:优先 Celery(进程隔离),否则 API 进程内 asyncio 后台执行。"""
|
||||
def dispatch_processing(task_id: str, stp_file_id: int, process_params: dict):
|
||||
"""调度 STP 处理任务:优先 Celery(进程隔离),否则 API 进程内 asyncio 后台执行。
|
||||
|
||||
入参只传 stp_file_id(D6):源文件由处理方按 PG 元数据从 RustFS 获取,
|
||||
不再跨进程传节点本地路径——API 与 Celery worker 容器文件系统不互通,
|
||||
传路径在容器化部署下必然失败。
|
||||
"""
|
||||
if _use_celery:
|
||||
process_stp_task.delay(task_id, file_path, stp_file_id, process_params)
|
||||
process_stp_task.delay(task_id, stp_file_id, process_params)
|
||||
logger.info(f"[DISPATCH] Celery 任务已调度: task_id={task_id}")
|
||||
return
|
||||
|
||||
task = asyncio.create_task(
|
||||
_run_with_limit(task_id, file_path, stp_file_id, process_params)
|
||||
_run_with_limit(task_id, stp_file_id, process_params)
|
||||
)
|
||||
_background_tasks.add(task)
|
||||
task.add_done_callback(_background_tasks.discard)
|
||||
|
||||
Reference in New Issue
Block a user