数据看板

This commit is contained in:
2026-08-25 18:01:30 +08:00
parent 6bc0f16006
commit a021f2fe60
9 changed files with 526 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
import hashlib
import json
import secrets
import shutil
import string
import threading
import time
@@ -401,6 +402,33 @@ def list_tasks(q: str = "", status: str = "", page: int = 1, page_size: int = 10
}
def merge_tasks(public_ids: list[str]) -> dict[str, Any]:
ids = list(dict.fromkeys(str(item).strip() for item in public_ids if str(item).strip()))
if not ids:
raise TaskError("MERGE_TASKS_REQUIRED", "至少需要一个任务 ID", 422)
if len(ids) > 50:
raise TaskError("MERGE_TASKS_LIMIT", "单次最多合并 50 个任务", 422)
tasks = [get_task(public_id) for public_id in ids]
return {"task_ids": ids, "tasks": tasks, "total": len(tasks)}
def delete_task(public_id: str) -> dict[str, Any]:
with connection() as conn:
row = conn.execute(
"SELECT id,status FROM research_tasks WHERE public_task_id=?", (public_id,)
).fetchone()
if not row:
raise TaskError("TASK_NOT_FOUND", "任务不存在", 404)
if row["status"] not in TERMINAL_STATUSES:
raise TaskError("TASK_STATUS_CONFLICT", "只能删除已结束任务", 409)
conn.execute("UPDATE research_tasks SET retry_of_task_id=NULL WHERE retry_of_task_id=?", (row["id"],))
conn.execute("DELETE FROM research_tasks WHERE id=?", (row["id"],))
folder = Config.FILE_STORAGE_PATH / public_id
if folder.exists() and folder.is_dir() and not folder.is_symlink():
shutil.rmtree(folder)
return {"task_id": public_id, "deleted": True}
def cancel_task(public_id: str, reason: str = "") -> dict[str, Any]:
crawler_task_id = None
with connection() as conn: