File size: 1,060 Bytes
e317359
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/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()