fix: clarify AI generation failure retry states
This commit is contained in:
@@ -222,6 +222,28 @@ def _notify_retry(callback, step, attempt, attempts, exc, model):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def _task_attempt_count(task, field):
|
||||
try:
|
||||
return int(getattr(task, field, 0) or 0)
|
||||
except (TypeError, ValueError):
|
||||
return 0
|
||||
|
||||
|
||||
def is_generatable_task(task):
|
||||
"""判断任务是否能由② AI生成执行或重试。"""
|
||||
|
||||
stage = str(getattr(task, "stage", "") or "")
|
||||
status = str(getattr(task, "status", "") or "")
|
||||
if status in {"running", "skipped"}:
|
||||
return False
|
||||
if stage == "collected":
|
||||
return True
|
||||
if stage == "generated" and status == "failed":
|
||||
return _task_attempt_count(task, "apply_attempts") == 0
|
||||
return False
|
||||
|
||||
|
||||
def generate_batch(tasks, prompts, ai_cfg=None, on_progress=None, should_stop=None):
|
||||
"""Generate titles first, then covers, and persist each successful task."""
|
||||
|
||||
@@ -256,7 +278,7 @@ def generate_batch(tasks, prompts, ai_cfg=None, on_progress=None, should_stop=No
|
||||
should_stop = should_stop or (lambda: False)
|
||||
eligible = [
|
||||
task for task in list(tasks)
|
||||
if getattr(task, "stage", None) == "collected"
|
||||
if is_generatable_task(task)
|
||||
]
|
||||
summary = {
|
||||
"ok": True,
|
||||
|
||||
Reference in New Issue
Block a user