diff --git a/jean-router/app.py b/jean-router/app.py index 407236e..d381bcc 100644 --- a/jean-router/app.py +++ b/jean-router/app.py @@ -133,24 +133,23 @@ def send_wol(): def jean_alive() -> bool: - """Verifie si le PC gaming est accessible (Jean ou Ollama)""" + """Verifie si le PC gaming est allume (TCP connect vers Jean ou Ollama)""" now = time.time() if now - jean_alive_cache["timestamp"] < 2: return jean_alive_cache["alive"] alive = False - try: - r = requests.get(f"http://{JEAN_WEB_HOST}:{JEAN_WEB_PORT}/api/presets", timeout=3) - alive = r.ok - except Exception: - pass - - if not alive: + for port in [JEAN_WEB_PORT, OLLAMA_DIRECT_PORT]: try: - r = requests.get(f"http://{OLLAMA_DIRECT_HOST}:{OLLAMA_DIRECT_PORT}/api/version", timeout=2) - alive = r.ok - except Exception: - pass + sock = socket.create_connection((JEAN_WEB_HOST, port), timeout=2) + sock.close() + alive = True + break + except ConnectionRefusedError: + alive = True # PC on, service down + break + except (socket.timeout, OSError): + continue # PC off ou inaccessible jean_alive_cache["alive"] = alive jean_alive_cache["timestamp"] = now