add pause resume controls to ui
This commit is contained in:
1 parent
3c7cb45bec
commit
d81e00ddbc
13 files changed
+367
-12
No files matched your search
@@ -13,6 +13,7 @@ def get_stats(self: Any, include_events: bool = False) -> dict:
|
||||
start_ts = self._start_ts
|
||||
last_log_ts = self._last_log_ts
|
||||
exit_code = self._exit_code
|
||||
paused = bool(getattr(self, "_paused", False) and self._proc is not None and self._proc.poll() is None)
|
||||
log_len = len(self._log)
|
||||
counters = dict(self._counters)
|
||||
fudai_last = dict(self._fudai_last)
|
||||
@@ -125,6 +126,7 @@ def get_stats(self: Any, include_events: bool = False) -> dict:
|
||||
|
||||
payload = {
|
||||
"running": bool(running),
|
||||
"paused": paused,
|
||||
"pid": pid,
|
||||
"start_ts": start_ts,
|
||||
"last_log_ts": last_log_ts,
|
||||
@@ -145,4 +147,3 @@ def get_stats(self: Any, include_events: bool = False) -> dict:
|
||||
payload["events"] = events[-200:]
|
||||
|
||||
return payload
|
||||
|
||||
@@ -182,7 +182,12 @@ def handle_get(handler, u, runner, csrf_token: str) -> None:
|
||||
qlow = q.lower()
|
||||
filtered = [l for l in cand if qlow in (l or "").lower()]
|
||||
return handler._send_json(
|
||||
{"next": total, "lines": filtered, "running": runner.is_running()}
|
||||
{
|
||||
"next": total,
|
||||
"lines": filtered,
|
||||
"running": runner.is_running(),
|
||||
"paused": runner.is_paused(),
|
||||
}
|
||||
)
|
||||
except Exception as e:
|
||||
import traceback
|
||||
@@ -192,7 +197,12 @@ def handle_get(handler, u, runner, csrf_token: str) -> None:
|
||||
level="ERROR",
|
||||
)
|
||||
return handler._send_json(
|
||||
{"next": 0, "lines": [], "running": runner.is_running()}
|
||||
{
|
||||
"next": 0,
|
||||
"lines": [],
|
||||
"running": runner.is_running(),
|
||||
"paused": runner.is_paused(),
|
||||
}
|
||||
)
|
||||
since = 0
|
||||
try:
|
||||
@@ -202,7 +212,12 @@ def handle_get(handler, u, runner, csrf_token: str) -> None:
|
||||
try:
|
||||
next_idx, lines = runner.get_logs_since(since)
|
||||
return handler._send_json(
|
||||
{"next": next_idx, "lines": lines, "running": runner.is_running()}
|
||||
{
|
||||
"next": next_idx,
|
||||
"lines": lines,
|
||||
"running": runner.is_running(),
|
||||
"paused": runner.is_paused(),
|
||||
}
|
||||
)
|
||||
except Exception as e:
|
||||
import traceback
|
||||
@@ -212,7 +227,12 @@ def handle_get(handler, u, runner, csrf_token: str) -> None:
|
||||
level="ERROR",
|
||||
)
|
||||
return handler._send_json(
|
||||
{"next": 0, "lines": [], "running": runner.is_running()}
|
||||
{
|
||||
"next": 0,
|
||||
"lines": [],
|
||||
"running": runner.is_running(),
|
||||
"paused": runner.is_paused(),
|
||||
}
|
||||
)
|
||||
if u.path == "/api/logfile-tail":
|
||||
qs = parse_qs(u.query)
|
||||
@@ -657,6 +677,28 @@ def handle_post(handler, u, runner, csrf_token: str) -> None:
|
||||
if u.path == "/api/force-stop":
|
||||
runner.force_stop()
|
||||
return handler._send_json({"ok": True, "message": "已执行强制停止"})
|
||||
if u.path == "/api/pause":
|
||||
ok = runner.pause()
|
||||
return handler._send_json(
|
||||
{
|
||||
"ok": bool(ok),
|
||||
"running": runner.is_running(),
|
||||
"paused": runner.is_paused(),
|
||||
"message": "已暂停" if ok else "暂停失败",
|
||||
},
|
||||
status=200 if ok else 409,
|
||||
)
|
||||
if u.path == "/api/resume":
|
||||
ok = runner.resume()
|
||||
return handler._send_json(
|
||||
{
|
||||
"ok": bool(ok),
|
||||
"running": runner.is_running(),
|
||||
"paused": runner.is_paused(),
|
||||
"message": "已继续" if ok else "继续失败",
|
||||
},
|
||||
status=200 if ok else 409,
|
||||
)
|
||||
if u.path == "/api/back-key":
|
||||
body = handler._read_json()
|
||||
requested_device_id = str(body.get("device_id") or "").strip()
|
||||
|
||||
Reference in new issue
Block a user