Buckets:

download
raw
1.4 kB
"""Health and readiness check endpoints."""
import datetime
from typing import Optional
from fastapi import APIRouter
from pulsar_relay.models import HealthResponse, ReadinessResponse
from pulsar_relay.storage.base import StorageBackend
router = APIRouter(tags=["health"])
# Storage backend will be injected
_storage: Optional[StorageBackend] = None
def set_storage(storage: StorageBackend) -> None:
"""Set the storage backend for health checks."""
global _storage
_storage = storage
@router.get("/health", response_model=HealthResponse)
async def health_check() -> HealthResponse:
"""Basic health check endpoint."""
return HealthResponse(status="healthy", timestamp=datetime.datetime.now(datetime.timezone.utc))
@router.get("/ready", response_model=ReadinessResponse)
async def readiness_check() -> ReadinessResponse:
"""Readiness check with dependency status."""
checks = {}
# Check storage
if _storage is not None:
try:
storage_healthy = await _storage.health_check()
checks["storage"] = "ok" if storage_healthy else "unhealthy"
except Exception as e:
checks["storage"] = f"error: {str(e)}"
else:
checks["storage"] = "not_initialized"
# Overall readiness
ready = all(status == "ok" for status in checks.values())
return ReadinessResponse(ready=ready, checks=checks)

Xet Storage Details

Size:
1.4 kB
·
Xet hash:
a7a825889d7dfd566027d82c7734dca767f7c58ce44bc09999cdd53e8b6a3fa1

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.