feat: add multi-server control panel and host-aware sync
This commit is contained in:
+21
-5
@@ -2,11 +2,13 @@
|
||||
Health check endpoints
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
import requests
|
||||
import logging
|
||||
from typing import Optional
|
||||
from urllib.parse import urlparse
|
||||
from app.config import settings
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -26,18 +28,31 @@ class HealthResponse(BaseModel):
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def resolve_ollama_host(host: Optional[str]) -> str:
|
||||
"""Resolve target Ollama host, optionally overridden by query parameter."""
|
||||
if not host:
|
||||
return settings.OLLAMA_HOST
|
||||
|
||||
parsed = urlparse(host.strip())
|
||||
if parsed.scheme not in {"http", "https"} or not parsed.netloc:
|
||||
raise HTTPException(status_code=422, detail="Invalid Ollama host URL")
|
||||
|
||||
return host.rstrip("/")
|
||||
|
||||
@router.get("/health", response_model=HealthResponse)
|
||||
async def health_check():
|
||||
async def health_check(host: Optional[str] = Query(default=None)):
|
||||
"""
|
||||
Health check dell'API e dello stato di Ollama
|
||||
|
||||
Returns:
|
||||
HealthResponse: Status dell'API e di Ollama
|
||||
"""
|
||||
target_host = resolve_ollama_host(host)
|
||||
try:
|
||||
# Check Ollama
|
||||
response = requests.get(
|
||||
f"{settings.OLLAMA_HOST}/api/tags",
|
||||
f"{target_host}/api/tags",
|
||||
timeout=settings.OLLAMA_TIMEOUT
|
||||
)
|
||||
ollama_status = "online" if response.status_code == 200 else "offline"
|
||||
@@ -52,13 +67,14 @@ async def health_check():
|
||||
)
|
||||
|
||||
@router.get("/ready")
|
||||
async def ready():
|
||||
async def ready(host: Optional[str] = Query(default=None)):
|
||||
"""
|
||||
Readiness probe per Kubernetes/Docker
|
||||
"""
|
||||
target_host = resolve_ollama_host(host)
|
||||
try:
|
||||
response = requests.get(
|
||||
f"{settings.OLLAMA_HOST}/api/tags",
|
||||
f"{target_host}/api/tags",
|
||||
timeout=5
|
||||
)
|
||||
if response.status_code == 200:
|
||||
|
||||
Reference in New Issue
Block a user