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,
|
||||
|
||||
@@ -275,10 +275,30 @@ class GenerateTaskTableModel(QAbstractTableModel):
|
||||
return task.account_name or task.alias or ""
|
||||
|
||||
def _status_text(self, task):
|
||||
if task.status == "failed":
|
||||
return self._failed_status_text(task)
|
||||
if task.status in self.STATUS_TEXT and task.status != "pending":
|
||||
return self.STATUS_TEXT[task.status]
|
||||
return self.STAGE_TEXT.get(task.stage, task.stage)
|
||||
|
||||
def _failed_status_text(self, task):
|
||||
collect_attempts = self._attempt_count(task, "collect_attempts")
|
||||
generate_attempts = self._attempt_count(task, "generate_attempts")
|
||||
apply_attempts = self._attempt_count(task, "apply_attempts")
|
||||
if apply_attempts > 0:
|
||||
return "更新失败"
|
||||
if generate_attempts > 0:
|
||||
return "生成失败"
|
||||
if collect_attempts > 0 or getattr(task, "stage", None) == "imported":
|
||||
return "采集失败"
|
||||
return "失败"
|
||||
|
||||
def _attempt_count(self, task, field):
|
||||
try:
|
||||
return int(getattr(task, field, 0) or 0)
|
||||
except (TypeError, ValueError):
|
||||
return 0
|
||||
|
||||
def _status_color(self, task):
|
||||
base_color = _status_base_color(getattr(task, "status", None))
|
||||
if base_color is not None:
|
||||
|
||||
@@ -470,10 +470,10 @@ class GenerateTab(QWidget):
|
||||
generate_cover = bool(self.generate_cover_checkbox.isChecked())
|
||||
tasks = [
|
||||
task for task in self.model.tasks
|
||||
if getattr(task, "stage", None) == "collected"
|
||||
if ai.is_generatable_task(task)
|
||||
]
|
||||
if not tasks:
|
||||
self._set_status("当前筛选结果没有可生成任务")
|
||||
self._set_status("当前筛选结果没有待生成或生成失败可重试任务;请先在①导入采集完成旧数据采集")
|
||||
return
|
||||
prompt_values = {
|
||||
"title": self.title_prompt_edit.toPlainText(),
|
||||
@@ -896,7 +896,7 @@ class GenerateTab(QWidget):
|
||||
if selected_status in (None, "all"):
|
||||
return True
|
||||
if selected_status == "to_generate":
|
||||
return task.stage == "collected" and task.status in {"success", "pending"}
|
||||
return ai.is_generatable_task(task) and task.status != "failed"
|
||||
if selected_status == "generated":
|
||||
return task.stage == "generated"
|
||||
if selected_status == "applied":
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from .widgets import *
|
||||
class GenerateWorker(BaseWorker):
|
||||
"""Generate titles and covers for collected tasks."""
|
||||
"""Generate titles and covers for eligible collected or failed generation tasks."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -39,7 +39,7 @@ class GenerateWorker(BaseWorker):
|
||||
self._account_by_alias = account_by_alias
|
||||
eligible = [
|
||||
task for task in self.tasks
|
||||
if getattr(task, "stage", None) == "collected"
|
||||
if ai.is_generatable_task(task)
|
||||
]
|
||||
self._eligible_total = len(eligible)
|
||||
self._task_positions = {
|
||||
|
||||
Reference in New Issue
Block a user