修复poll降频检测时间BUG

This commit is contained in:
2026-07-03 12:31:01 +08:00
parent 28b1d24173
commit e4cf7799a4
2 changed files with 55 additions and 15 deletions
@@ -271,7 +271,7 @@ async def _schedule_next_poll(
)
async def _run(task_id: str):
async def _run(task_id: str, *, force_due: bool = False):
async with async_session() as db:
result = await db.execute(select(ChatGenerationTask).where(
ChatGenerationTask.id == task_id,
@@ -296,7 +296,10 @@ async def _run(task_id: str):
current_time = _now()
if is_video_generation_task(task):
ensure_video_poll_fields(task, now=current_time)
if is_poll_not_due(task, now=current_time):
# dispatcher / recovery 已经在投递前确认到期时,会传 force_due=True。
# 这样可以避免投递侧为了防重复消费临时写入的 next_poll_at
# 又被当前 worker 当成“业务下一次轮询时间”而误判未到期。
if not force_due and is_poll_not_due(task, now=current_time):
await db.commit()
await _skip_not_due(task)
return
@@ -481,9 +484,9 @@ async def _run(task_id: str):
if celery_app:
@celery_app.task(name="generation.poll_generation_task", bind=True, max_retries=3, default_retry_delay=30)
def poll_generation_task(self, task_id: str):
def poll_generation_task(self, task_id: str, force_due: bool = False):
try:
return run_async(_run(task_id))
return run_async(_run(task_id, force_due=bool(force_due)))
except Exception as exc:
# 只重试基础设施异常;供应商失败/业务失败已在 _run 内处理。
retries = int(getattr(self.request, "retries", 0) or 0) + 1