From 507ca4d6b8a0bc099b8ac8648c1b8ccd89ae4043 Mon Sep 17 00:00:00 2001 From: CI Bot Date: Wed, 15 Jul 2026 12:19:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=89=AA=E8=BE=91=E8=AE=A1=E5=88=92P0+P?= =?UTF-8?q?1=E4=BF=AE=E5=A4=8D=20-=20asset=5Fids=E4=BC=A0=E9=80=92=20+=20r?= =?UTF-8?q?esult=5Fcount=E4=BF=AE=E6=AD=A3=20+=20total=5Fduration=E5=9B=9E?= =?UTF-8?q?=E5=86=99=20+=20logs=E5=9F=8B=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit P0修复: - 触发生成时将plan.config.asset_ids传递到GenerationTask - 同时补全project_id字段(之前为空字符串) P1修复: - result_count: 剪辑计划多片段合成1个成片,改为1(之前误存为clip数) - total_duration: 渲染成功后回写实际输出时长到EditPlan.total_duration - logs: 新增5个关键节点日志埋点(render_start/download_done/download_failed/render_complete/render_failed) - 下载完成后进度推进到30%,便于前端展示素材下载中状态 --- .../app/api/routes/edit_plans_generation.py | 5 +- .../worker_app/tasks/edit_plan_generation.py | 57 ++++++++++++++++++- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/apps/api/app/api/routes/edit_plans_generation.py b/apps/api/app/api/routes/edit_plans_generation.py index 5a1a65c9e..2d61302d9 100755 --- a/apps/api/app/api/routes/edit_plans_generation.py +++ b/apps/api/app/api/routes/edit_plans_generation.py @@ -253,12 +253,15 @@ def generate_plan( gen_task_use_case = CreateGenerationTaskUseCase(gen_task_repo) plan = svc.get_plan_or_raise(plan_id) + # 从 plan.config 中读取 asset_ids 并传递给 GenerationTask + config_asset_ids = (plan.config or {}).get("asset_ids", []) gen_task = gen_task_use_case.execute( CreateGenerationTaskCommand( - project_id="", + project_id=plan.project_id or "", template_id=plan.template_id, created_by_user_id=current_user.user.id, source_edit_plan_id=plan_id, + asset_ids=list(config_asset_ids) if config_asset_ids else [], ) ) diff --git a/apps/worker/worker_app/tasks/edit_plan_generation.py b/apps/worker/worker_app/tasks/edit_plan_generation.py index b6c13001a..28061fb35 100755 --- a/apps/worker/worker_app/tasks/edit_plan_generation.py +++ b/apps/worker/worker_app/tasks/edit_plan_generation.py @@ -107,6 +107,14 @@ def _mark_plan_failed(plan_repo, plan_id, gen_task_repo, generation_task_id, err gen_task.status = "failed" gen_task.error_message = error_msg gen_task.completed_at = datetime.now(timezone.utc) + try: + gen_task.append_log( + stage="render_failed", + message=error_msg[:500], + level="ERROR", + ) + except Exception: + pass gen_task_repo.update(gen_task) @@ -160,9 +168,11 @@ def _finalize_render_success( clip.mark_rendered() clip_repo.update(clip) - # 更新 EditPlan 状态为 completed + # 更新 EditPlan 状态为 completed + 回写实际渲染时长 plan.config["rendered_url"] = output_url or "" plan.config["rendered_storage_key"] = storage_key + if hasattr(plan, "total_duration") and duration > 0: + plan.total_duration = duration plan.mark_completed() plan_repo.update(plan) @@ -172,7 +182,15 @@ def _finalize_render_success( if gen_task: gen_task.status = "completed" gen_task.progress = 100.0 - gen_task.result_count = len(rendered_clip_ids) + # 剪辑计划是多片段合成 1 个成片,result_count = 1 + gen_task.result_count = 1 + gen_task.append_log( + stage="render_complete", + message=f"渲染完成,输出时长 {duration:.1f}s", + level="INFO", + engine=engine, + clip_count=len(rendered_clip_ids), + ) gen_task.completed_at = datetime.now(timezone.utc) gen_task_repo.update(gen_task) @@ -377,6 +395,13 @@ def render_edit_plan(self, plan_id: str) -> dict: if gen_task: gen_task.status = "running" gen_task.started_at = datetime.now(timezone.utc) + gen_task.append_log( + stage="render_start", + message=f"开始渲染,引擎 {engine},片段数 {len(clips)}", + level="INFO", + engine=engine, + clip_count=len(clips), + ) gen_task_repo.update(gen_task) # 3. 下载素材并构建 asset_path_map @@ -441,9 +466,28 @@ def render_edit_plan(self, plan_id: str) -> dict: gen_task.status = "failed" gen_task.error_message = "所有片段素材下载失败" gen_task.completed_at = datetime.now(timezone.utc) + gen_task.append_log( + stage="download_failed", + message="所有片段素材下载失败", + level="ERROR", + ) gen_task_repo.update(gen_task) return {"status": "error", "message": "所有片段素材下载失败"} + # 素材下载完成,记录日志 + if generation_task_id: + gen_task = gen_task_repo.get(generation_task_id) + if gen_task: + gen_task.append_log( + stage="download_done", + message=f"素材下载完成,成功 {len(asset_path_map)} 个,失败 {len(failed_clip_ids)} 个", + level="INFO", + success_count=len(asset_path_map), + failed_count=len(failed_clip_ids), + ) + gen_task.progress = 30.0 + gen_task_repo.update(gen_task) + # 4. 根据引擎选择渲染方式 if engine == "unified": result = _render_with_unified( @@ -495,6 +539,15 @@ def render_edit_plan(self, plan_id: str) -> dict: gen_task.status = "failed" gen_task.error_message = f"渲染异常: {type(exc).__name__}: {exc}" gen_task.completed_at = datetime.now(timezone.utc) + try: + gen_task.append_log( + stage="render_failed", + message=f"渲染异常: {type(exc).__name__}: {str(exc)[:500]}", + level="ERROR", + exception_type=type(exc).__name__, + ) + except Exception: + pass gen_task_repo.update(gen_task) logger.info( "GenerationTask 已标记为 failed: task_id=%s plan_id=%s",