From 4a2355a9029433cf8cf88b0a271381259d40ffb6 Mon Sep 17 00:00:00 2001 From: wwwwwwwww <526125649@qq.com> Date: Fri, 14 Aug 2026 15:47:51 +0800 Subject: [PATCH] 1 --- video-gen-api/app/tasks/scheduled_tasks.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/video-gen-api/app/tasks/scheduled_tasks.py b/video-gen-api/app/tasks/scheduled_tasks.py index 04a4daab..375aaf6f 100644 --- a/video-gen-api/app/tasks/scheduled_tasks.py +++ b/video-gen-api/app/tasks/scheduled_tasks.py @@ -44,13 +44,12 @@ async def _update_task_status(task_id: str, status: str, error_msg: str | None = await db.commit() -def _execute_internal_method(config: str | None) -> dict: +async def _execute_internal_method(config: str | None) -> dict: """执行内部方法调用。 配置 JSON 中 module 和 function 指定要调用的函数,其余字段作为 kwargs 传入。 支持同步函数和异步函数(async def)。 """ - import asyncio import importlib from inspect import iscoroutinefunction @@ -69,8 +68,8 @@ def _execute_internal_method(config: str | None) -> dict: # 剩余字段作为 kwargs 传给函数 start = time.monotonic() if iscoroutinefunction(func): - # 异步函数:在当前事件循环中 await - result = asyncio.get_event_loop().run_until_complete(func(**cfg)) + # 异步函数:直接 await + result = await func(**cfg) else: result = func(**cfg) duration_ms = int((time.monotonic() - start) * 1000) @@ -97,7 +96,7 @@ def execute_scheduled_task(self, task_id: str): task_config = task.config try: - exec_result = _execute_internal_method(task_config) + exec_result = await _execute_internal_method(task_config) await _update_task_status(task_id, "success") logger.info("定时任务执行成功: %s -> %s", task_id, exec_result) except Exception as e: