Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32eebf3dd1 | ||
|
|
d9c9f0c633 |
@@ -5,3 +5,4 @@ data/cookies_*.json
|
||||
logs/
|
||||
out/
|
||||
data/exports/
|
||||
data/auto_state/
|
||||
@@ -308,11 +308,19 @@ def api_task_detail(tid):
|
||||
result["run_page"] = page
|
||||
result["run_pages"] = pages
|
||||
result["run_page_size"] = page_size
|
||||
# auto 状态数量 (独立文件)
|
||||
# auto 状态数量: 运行中优先读内存实时值, 否则读状态文件
|
||||
if task.get("mode") == "auto":
|
||||
live_v = live_p = None
|
||||
with JOBS_LOCK:
|
||||
job = JOBS.get(tid)
|
||||
if job:
|
||||
live_v = getattr(job, "_auto_visited", None)
|
||||
live_p = getattr(job, "_auto_pending", None)
|
||||
st = store.load_auto_state(tid, task)
|
||||
result["auto_pending_count"] = len(st.get("pending", []))
|
||||
result["auto_visited_count"] = len(st.get("visited", []))
|
||||
result["auto_pending_count"] = (
|
||||
live_p if live_p is not None else len(st.get("pending", [])))
|
||||
result["auto_visited_count"] = (
|
||||
live_v if live_v is not None else len(st.get("visited", [])))
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"pending": [],
|
||||
"visited": [
|
||||
"http://127.0.0.1:38081/p2",
|
||||
"http://127.0.0.1:38081/p5",
|
||||
"http://127.0.0.1:38081/p3",
|
||||
"http://127.0.0.1:38081/",
|
||||
"http://127.0.0.1:38081/p1",
|
||||
"http://127.0.0.1:38081/p4"
|
||||
]
|
||||
}
|
||||
@@ -226,6 +226,9 @@ class CrawlJob:
|
||||
self.persist = persist # callable(task_id, run)
|
||||
self._stop = threading.Event()
|
||||
self._pause = threading.Event()
|
||||
# 运行中的 auto 实时状态 (供详情接口读取; 任务结束时由状态文件兜底)
|
||||
self._auto_visited = None
|
||||
self._auto_pending = None
|
||||
self._cfg_lock = threading.RLock()
|
||||
self.thread = None
|
||||
|
||||
@@ -630,6 +633,8 @@ class CrawlJob:
|
||||
queued.add(normalize_url(u))
|
||||
|
||||
run["progress"]["total"] = len(queue)
|
||||
self._auto_visited = len(visited)
|
||||
self._auto_pending = len(queue)
|
||||
self._persist()
|
||||
|
||||
p, browser, ctx, page, cookie_file = self._open_browser()
|
||||
@@ -650,6 +655,8 @@ class CrawlJob:
|
||||
if key in visited and url != seed: # 起始网址不去重, 其余已爬跳过
|
||||
continue
|
||||
visited.add(key)
|
||||
self._auto_visited = len(visited)
|
||||
self._auto_pending = len(queue)
|
||||
idx = len(visited)
|
||||
run["progress"]["current_url"] = url
|
||||
run["progress"]["done"] = len(visited)
|
||||
@@ -666,6 +673,7 @@ class CrawlJob:
|
||||
if lk not in visited and lk not in queued:
|
||||
queued.add(lk)
|
||||
queue.append((link, depth + 1, url))
|
||||
self._auto_pending = len(queue) # 新链接入队后实时刷新
|
||||
if entry["status"] == "OK":
|
||||
self._delay()
|
||||
run["progress"]["total"] = len(visited)
|
||||
|
||||
Reference in New Issue
Block a user