M35: harden the shared public demo

This commit is contained in:
NuklearRabbit
2026-08-10 22:32:58 +02:00
parent c7492bf6ad
commit 809ba0ddcc
9 changed files with 142 additions and 22 deletions
+17 -5
View File
@@ -1,5 +1,7 @@
from __future__ import annotations
import threading
import time
from datetime import UTC, datetime, timedelta
from typing import Literal
@@ -18,6 +20,9 @@ from app.schemas import (
)
settings = get_settings()
_hub_health_lock = threading.Lock()
_hub_health_cached_at = 0.0
_hub_health_cached_value: bool | None = None
# The 4 canonical Fleet Ops n8n workflows (see n8n/workflows/MANIFEST.md). All 4 are
# built (all with their full node set saved).
@@ -278,8 +283,15 @@ def _check_hub_reachable() -> bool | None:
`None` means not configured / not checked, never a guess."""
if not settings.mcp_hub_base_url:
return None
try:
response = httpx.get(f"{settings.mcp_hub_base_url.rstrip('/')}/health", timeout=1.5)
return response.status_code == 200
except httpx.HTTPError:
return False
global _hub_health_cached_at, _hub_health_cached_value
now = time.monotonic()
with _hub_health_lock:
if now - _hub_health_cached_at < settings.mcp_hub_health_cache_seconds:
return _hub_health_cached_value
try:
response = httpx.get(f"{settings.mcp_hub_base_url.rstrip('/')}/health", timeout=1.5)
_hub_health_cached_value = response.status_code == 200
except httpx.HTTPError:
_hub_health_cached_value = False
_hub_health_cached_at = time.monotonic()
return _hub_health_cached_value