M35: harden the shared public demo
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user