jean-router: detection PC via TCP connect au lieu de HTTP
- TCP connect vers 8090 ou 11434 (pas de requete HTTP) - ConnectionRefused = PC allume (service down) - Timeout = PC eteint → WoL - Plus de spam HTTP vers un serveur bloque
This commit is contained in:
+11
-12
@@ -133,24 +133,23 @@ def send_wol():
|
|||||||
|
|
||||||
|
|
||||||
def jean_alive() -> bool:
|
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()
|
now = time.time()
|
||||||
if now - jean_alive_cache["timestamp"] < 2:
|
if now - jean_alive_cache["timestamp"] < 2:
|
||||||
return jean_alive_cache["alive"]
|
return jean_alive_cache["alive"]
|
||||||
|
|
||||||
alive = False
|
alive = False
|
||||||
try:
|
for port in [JEAN_WEB_PORT, OLLAMA_DIRECT_PORT]:
|
||||||
r = requests.get(f"http://{JEAN_WEB_HOST}:{JEAN_WEB_PORT}/api/presets", timeout=3)
|
|
||||||
alive = r.ok
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if not alive:
|
|
||||||
try:
|
try:
|
||||||
r = requests.get(f"http://{OLLAMA_DIRECT_HOST}:{OLLAMA_DIRECT_PORT}/api/version", timeout=2)
|
sock = socket.create_connection((JEAN_WEB_HOST, port), timeout=2)
|
||||||
alive = r.ok
|
sock.close()
|
||||||
except Exception:
|
alive = True
|
||||||
pass
|
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["alive"] = alive
|
||||||
jean_alive_cache["timestamp"] = now
|
jean_alive_cache["timestamp"] = now
|
||||||
|
|||||||
Reference in New Issue
Block a user