LiveHouse-TS / scripts /check_cloud_health.py
ziyuzhou02's picture
Deploy GitHub main 3feb6cda1511
e317359 verified
Raw History Blame Contribute Delete
1.06 kB
#!/usr/bin/env python3
"""Lightweight remote watchdog; no model dependencies or local operator needed."""
from __future__ import annotations
import json
import os
import time
from urllib.request import Request, urlopen
from urllib.error import HTTPError, URLError
def main():
url = os.getenv("HF_SPACE_URL", "https://thinkcatlab-livehouse-ts.hf.space").rstrip("/")
error = ""
for attempt in range(4):
try:
with urlopen(Request(url + "/healthz", headers={"User-Agent":"LiveHouse-TS-organization-healthcheck"}), timeout=45) as response:
payload = json.load(response)
if not payload.get("ok"):
raise ValueError("Remote evaluator/checkpoint is not healthy")
print(json.dumps(payload, indent=2))
return
except (HTTPError, URLError, TimeoutError, ValueError) as exc:
error = str(exc)
if attempt < 3:
time.sleep(30)
raise SystemExit("Cloud health check failed: " + error)
if __name__ == "__main__":
main()