#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""probe_ccs.py —— ccs 生产跑 1~63s 却 0 新增：查 args/翻页/判重"""
import json, shlex, subprocess, time, re
D = "/root/gov_crawler/"; f = "crawl_ccs.py"
cfg = json.load(open(D + "daily_crawl_config.json", encoding="utf-8"))
lst = cfg if isinstance(cfg, list) else cfg.get("tasks", cfg.get("scripts", []))
ent = [c for c in lst if c.get("script") == f]
print("config:", json.dumps(ent[0], ensure_ascii=False) if ent else "（不在 config）")
src = open(D + f, encoding="utf-8").read()
print("\n=== 翻页/阈值/判重关键行 ===")
for i, ln in enumerate(src.split("\n"), 1):
    if re.search(r"range\(|MAX_PG|max_pages|THRESHOLD|CUTOFF|SELECT .*gov_raw|INSERT|已有|DUP|dup", ln):
        print("  L%-4d %s" % (i, ln.strip()[:108]))
a = shlex.split((ent[0].get("args") or "") if ent else "")
print("\n=== 按调度器方式跑 (args=%r) ===" % " ".join(a))
t0 = time.time()
try:
    r = subprocess.run(["python3", D + f] + a, capture_output=True, text=True, timeout=150, cwd=D)
    print("EXIT=%d 耗时=%.0fs" % (r.returncode, time.time() - t0))
    ls = [y for y in (r.stdout or "").split("\n") if y.strip()]
    for x in ls[:4] + ls[-4:]: print("   ", x[:108])
except subprocess.TimeoutExpired:
    print("⏱ >150s")
