feat: add selected task reset actions

This commit is contained in:
chengma
2026-06-30 11:50:49 +08:00
parent 580a7a570d
commit f7ea9ec0fa
6 changed files with 412 additions and 8 deletions
+75
View File
@@ -518,6 +518,16 @@ def list_tasks(batch_id=None, stage=None, status=None, alias=None, path=None, co
return _fetch_all(database, sql, params, Task)
def get_task(task_id, path=None, conn=None):
with _connection(conn, path) as database:
return _fetch_one(
database,
"SELECT * FROM tasks WHERE id = ?",
(int(task_id),),
Task,
)
def mark_running(task_id, phase, path=None, conn=None) -> None:
_attempt_field(phase)
with _connection(conn, path) as database:
@@ -639,6 +649,71 @@ def set_applied(task_id, committed, error=None, path=None, conn=None) -> None:
)
def reset_generated(task_id, delete_file=False, path=None, conn=None) -> dict:
"""Clear local AI result and move the task back to collected state."""
with _connection(conn, path) as database:
before = get_task(task_id, conn=database)
if before is None:
raise DbError(f"任务不存在: {task_id}")
new_cover_path = before.new_cover_path
deleted_file = None
if delete_file:
raise DbError("重置生成结果默认不删除本地新封面文件,请手动确认后清理")
now = _now()
with database:
database.execute(
"""
UPDATE tasks
SET new_title = NULL,
new_cover_path = NULL,
stage = 'collected',
status = 'success',
last_error = NULL,
generated_at = NULL,
updated_at = ?
WHERE id = ?
""",
(now, int(task_id)),
)
after = get_task(task_id, conn=database)
return {
"task_id": int(task_id),
"before": before,
"after": after,
"new_cover_path": new_cover_path,
"deleted_file": deleted_file,
}
def reset_apply_status(task_id, path=None, conn=None) -> dict:
"""Move a generated/applied local task back to pending update state."""
with _connection(conn, path) as database:
before = get_task(task_id, conn=database)
if before is None:
raise DbError(f"任务不存在: {task_id}")
now = _now()
with database:
database.execute(
"""
UPDATE tasks
SET stage = 'generated',
status = 'pending',
last_error = NULL,
updated_at = ?
WHERE id = ?
""",
(now, int(task_id)),
)
after = get_task(task_id, conn=database)
return {
"task_id": int(task_id),
"before": before,
"after": after,
}
def create_run_log(
run_type,
dry_run=False,