爆款开头API开发完成文件追加

This commit is contained in:
2026-06-10 15:23:03 +08:00
parent b4a9ca9e9b
commit fa2e298efa
12 changed files with 115 additions and 11 deletions
@@ -13,6 +13,8 @@ from app.services.generation_refund_service import mark_chat_generation_task_fai
from app.services.generation_provider_service import poll_provider_task
from app.tasks.celery_app import celery_app
ALLOWED_GENERATION_MODES = {"chatapi_async", "hot_opening_replicate"}
def _is_success(status: str) -> bool:
return status in ("succeeded", "success", "completed", "done")
@@ -29,6 +31,12 @@ def _engine_snapshot(task: ChatGenerationTask) -> dict:
return {}
async def _notify_finished(db, task: ChatGenerationTask) -> None:
from app.services.generation_module_hook_service import notify_chat_generation_task_finished
await notify_chat_generation_task_finished(db, task)
async def _reload_task(db, task_id: str) -> ChatGenerationTask | None:
"""
rollback 后重新查询任务对象。
@@ -54,7 +62,7 @@ async def _run(task_id: str):
ChatGenerationTask.deleted_at.is_(None),
).with_for_update().limit(1))
task = result.scalar_one_or_none()
if not task or task.generation_mode != "chatapi_async":
if not task or task.generation_mode not in ALLOWED_GENERATION_MODES:
return
# 只处理正在生成,且处于远程等待/轮询中的任务。
@@ -68,6 +76,7 @@ async def _run(task_id: str):
error_message="任务轮询超时",
pipeline_stage="timeout",
)
await _notify_finished(db, task)
await db.commit()
await log_task_event(task, event_type="TASK_TIMEOUT", to_status="failed", to_stage="timeout")
return
@@ -79,6 +88,7 @@ async def _run(task_id: str):
error_message="缺少外部任务ID",
pipeline_stage="failed",
)
await _notify_finished(db, task)
await db.commit()
await log_task_event(task, event_type="POLL_FAILED", message=task.error_message)
return
@@ -130,6 +140,7 @@ async def _run(task_id: str):
error_message="供应商任务成功但未返回结果URL",
pipeline_stage="failed",
)
await _notify_finished(db, task)
await db.commit()
await log_task_event(task, event_type="POLL_FAILED", message=task.error_message)
return
@@ -153,6 +164,7 @@ async def _run(task_id: str):
error_message=poll_result.get("error") or f"供应商任务失败: {status}",
pipeline_stage="failed",
)
await _notify_finished(db, task)
await db.commit()
await log_task_event(task, event_type="POLL_FAILED", message=task.error_message, detail=poll_result)
return
@@ -194,6 +206,7 @@ async def _run(task_id: str):
error_message=error_message,
pipeline_stage="failed",
)
await _notify_finished(db, task)
await db.commit()
await log_task_event(task, event_type="POLL_FAILED", message=task.error_message)
else: