add health endpoint for gateway and everos
This commit is contained in:
24
core/api.py
24
core/api.py
@ -66,6 +66,30 @@ def create_app(
|
||||
if not service.authenticate_user(user_id, user_key):
|
||||
raise HTTPException(status_code=401, detail="invalid user credentials")
|
||||
|
||||
@router.get("/health")
|
||||
async def health() -> dict[str, Any]:
|
||||
try:
|
||||
everos_health = await client.health_check()
|
||||
except Exception as exc:
|
||||
return {
|
||||
"status": "degraded",
|
||||
"api": {"status": "ok"},
|
||||
"everos": {
|
||||
"status": "unavailable",
|
||||
"base_url": cfg.everos_base_url,
|
||||
"error": str(exc),
|
||||
},
|
||||
}
|
||||
return {
|
||||
"status": "ok",
|
||||
"api": {"status": "ok"},
|
||||
"everos": {
|
||||
"status": "ok",
|
||||
"base_url": cfg.everos_base_url,
|
||||
"data": everos_health,
|
||||
},
|
||||
}
|
||||
|
||||
@router.post("/users")
|
||||
async def create_user(request: UserCreateRequest) -> dict[str, Any]:
|
||||
return service.create_user(request.user_id)
|
||||
|
||||
@ -31,6 +31,15 @@ class EverOSClient:
|
||||
async def search_memory(self, payload: dict[str, Any]) -> dict[str, Any]:
|
||||
return await self._post("/api/v1/memory/search", payload)
|
||||
|
||||
async def health_check(self) -> dict[str, Any]:
|
||||
async with httpx.AsyncClient(
|
||||
base_url=self.base_url,
|
||||
timeout=self.timeout,
|
||||
) as client:
|
||||
response = await client.get("/health")
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
async def _post(self, path: str, payload: dict[str, Any]) -> dict[str, Any]:
|
||||
async with httpx.AsyncClient(
|
||||
base_url=self.base_url,
|
||||
|
||||
Reference in New Issue
Block a user