tiandytdd

This commit is contained in:
Ankle committed 2026-09-15 11:32:36 +08:00
1 parent ddea6d0578
commit 5746fa10db
5 files changed
+122 -20

No files matched your search

+24 -3
View File
@@ -58,7 +58,7 @@ def transient_api_failure(result: subprocess.CompletedProcess[str]) -> bool:
if result.returncode in TRANSIENT_CURL_EXIT_CODES:
return True
detail = f"{result.stdout}\n{result.stderr}".lower()
return any(marker in detail for marker in (
return bool(re.search(r"container(?:\s+[0-9a-f]+)?\s+is not running", detail)) or any(marker in detail for marker in (
"container is not running",
"container is restarting",
"no such container",
@@ -138,6 +138,25 @@ def wait_for_scan_http(timeout: float = API_RECOVERY_TIMEOUT) -> bool:
return False
def wait_for_scan_http_stable(
timeout: float = 180.0, stable_seconds: float = 15.0
) -> bool:
"""Wait until scan HTTP stays healthy across the systemd restart window."""
deadline = time.monotonic() + timeout
ready_since: float | None = None
while time.monotonic() < deadline:
now = time.monotonic()
if scan_http_ready():
if ready_since is None:
ready_since = now
elif now - ready_since >= stable_seconds:
return True
else:
ready_since = None
time.sleep(API_RECOVERY_POLL_INTERVAL)
return False
def api(method: str, path: str, body: dict | None = None, timeout: int = 60) -> dict:
global _HELPER_READY
command = api_command(method, path, body, timeout)
@@ -218,8 +237,10 @@ def parse_ptz_payload(payload: dict) -> dict[str, int]:
return result
def get_ptz() -> dict[str, int]:
payload = api("GET", "/api/v1/ptz?source=scan_calibrator", timeout=50)
def get_ptz(timeout: int = 50) -> dict[str, int]:
payload = api(
"GET", "/api/v1/ptz?source=scan_calibrator", timeout=timeout
)
return parse_ptz_payload(payload)