fix: 修改一下生图的 bug

This commit is contained in:
2026-08-31 21:56:48 +08:00
parent 2a667b4f3b
commit 8b54f7ed1e
14 changed files with 636 additions and 47 deletions
+16 -1
View File
@@ -206,11 +206,26 @@ async def claim_next_item(owner: str, lease_seconds: int = 90) -> ClaimedItem |
async def mark_waiting_provider(item_id: str, provider_task_id: str, provider_task_kind: str, delay_seconds: int = 3) -> None:
"""先持久化外部任务 ID,再安排下一次查询,是避免重启重复扣费的关键提交点。"""
"""持久化外部任务 ID 并安排下一次查询。
取消可能恰好发生在 Worker 轮询供应商的网络请求期间。这里在同一事务内
再次检查父任务,避免已取消任务被写回 waiting_provider 后永远不再被领取。
"""
async with get_session_factory()() as db:
item = await db.get(BackgroundJobItem, uuid.UUID(item_id))
if item is None:
return
job = await db.get(BackgroundJob, item.job_id)
if job is None or job.cancel_requested:
item.status = ITEM_CANCELLED
item.lease_owner = None
item.lease_expires_at = None
item.next_run_at = None
item.completed_at = utcnow()
if job is not None:
await _refresh_job_status(db, job)
await db.commit()
return
item.provider_task_id = provider_task_id
item.provider_task_kind = provider_task_kind
item.status = ITEM_WAITING_PROVIDER