fix: 一次保存学习配置,改代理后重开任务
This commit is contained in:
@@ -48,6 +48,8 @@ _assign_lock = threading.Lock()
|
||||
_holds: dict[str, int] = {}
|
||||
_refresh_lock = threading.Lock()
|
||||
_stop: threading.Event | None = None
|
||||
_probe_guard = threading.Lock()
|
||||
_probe_state = {"running": False, "count": 0, "error": ""}
|
||||
|
||||
|
||||
def _now() -> datetime:
|
||||
@@ -507,7 +509,44 @@ def probe_one(node_id: int) -> dict:
|
||||
return view_item(node)
|
||||
|
||||
|
||||
def request_probe(ids: list[int] | None = None) -> dict:
|
||||
"""整表探测放到后台,避免一次请求卡住到超时。"""
|
||||
with _probe_guard:
|
||||
if _probe_state["running"]:
|
||||
return {"running": True, "count": _probe_state["count"], "items": []}
|
||||
_probe_state["running"] = True
|
||||
_probe_state["error"] = ""
|
||||
_probe_state["count"] = 0
|
||||
|
||||
def work() -> None:
|
||||
try:
|
||||
result = probe_ids(ids)
|
||||
with _probe_guard:
|
||||
_probe_state["count"] = int(result.get("count") or 0)
|
||||
_probe_state["error"] = ""
|
||||
except Exception as exc:
|
||||
with _probe_guard:
|
||||
_probe_state["error"] = str(exc)[:200]
|
||||
finally:
|
||||
with _probe_guard:
|
||||
_probe_state["running"] = False
|
||||
|
||||
threading.Thread(target=work, name="euniv-proxy-probe", daemon=True).start()
|
||||
return {"running": True, "count": 0, "items": []}
|
||||
|
||||
|
||||
def probe_state() -> dict:
|
||||
with _probe_guard:
|
||||
return {
|
||||
"running": _probe_state["running"],
|
||||
"count": _probe_state["count"],
|
||||
"error": _probe_state["error"],
|
||||
}
|
||||
|
||||
|
||||
def probe_ids(ids: list[int] | None = None) -> dict:
|
||||
if ids is not None and not ids:
|
||||
return {"ok": True, "count": 0, "items": []}
|
||||
with SessionLocal() as db:
|
||||
if ids:
|
||||
wanted = []
|
||||
|
||||
Reference in New Issue
Block a user