支持验收项目独立启动爬虫采集
This commit is contained in:
@@ -950,7 +950,7 @@ def create_acceptance_task(data: dict[str, Any]) -> dict[str, Any]:
|
||||
raise TaskError("KEYWORD_LIMIT_EXCEEDED", "单次最多支持 20 个搜索词", 422)
|
||||
if method in {"screenshot", "combined"} and not keywords:
|
||||
raise TaskError("KEYWORD_REQUIRED", "截图取证请至少输入一个搜索词", 422)
|
||||
if method in {"data-analysis", "combined"} and not links:
|
||||
if method in {"data-analysis", "combined"} and not links and not keywords:
|
||||
raise TaskError("FEISHU_LINK_REQUIRED", "笔记收录请至少输入一个公开飞书链接", 422)
|
||||
resources = {
|
||||
"cookie_count": max(0, int(raw_resources.get("cookie_count") or 0)),
|
||||
@@ -1194,6 +1194,35 @@ def collect_acceptance_now(public_id: str) -> dict[str, Any]:
|
||||
return _copy_acceptance_task(public_id, trigger_source="acceptance")
|
||||
|
||||
|
||||
def collect_acceptance_crawler_now(public_id: str) -> dict[str, Any]:
|
||||
"""按项目搜索词启动独立的 Cookie 爬虫采集批次,不下发截图设备。"""
|
||||
with connection() as conn:
|
||||
task = conn.execute("SELECT * FROM acceptance_tasks WHERE public_task_id=?", (public_id,)).fetchone()
|
||||
if not task:
|
||||
raise TaskError("ACCEPTANCE_TASK_NOT_FOUND", "验收任务不存在", 404)
|
||||
root_id = task["scheduled_from_task_id"] or task["id"]
|
||||
root = conn.execute("SELECT * FROM acceptance_tasks WHERE id=?", (root_id,)).fetchone()
|
||||
keywords = [row["keyword"] for row in conn.execute("SELECT keyword FROM acceptance_keywords WHERE task_id=? ORDER BY keyword_order", (root_id,)).fetchall()]
|
||||
matches = [row["keyword"] for row in conn.execute("SELECT keyword FROM acceptance_match_keywords WHERE task_id=? ORDER BY keyword_order", (root_id,)).fetchall()]
|
||||
child = create_acceptance_task({
|
||||
"name": f"{root['name']}|爬虫数据采集",
|
||||
"acceptance_method": "data-analysis",
|
||||
"feishu_links": [],
|
||||
"keywords": keywords,
|
||||
"match_keywords": matches,
|
||||
"created_by_id": root["created_by_id"],
|
||||
"created_by_name": root["created_by_name"],
|
||||
"trigger_source": "acceptance",
|
||||
})
|
||||
with connection() as conn:
|
||||
conn.execute(
|
||||
"""UPDATE acceptance_tasks SET scheduled_from_task_id=?,dashboard_batch_key=?
|
||||
WHERE public_task_id=?""",
|
||||
(root_id, root["dashboard_batch_key"], child["task_id"]),
|
||||
)
|
||||
return get_acceptance_task(child["task_id"])
|
||||
|
||||
|
||||
def run_due_acceptance_schedules() -> int:
|
||||
current = datetime.now().astimezone()
|
||||
now = current.isoformat(timespec="seconds")
|
||||
|
||||
Reference in New Issue
Block a user