31 lines
702 B
Python
31 lines
702 B
Python
from contextlib import asynccontextmanager
|
|
from typing import List
|
|
|
|
from fastapi import FastAPI
|
|
from servers.base import BaseService
|
|
from servers.database.server import database_service
|
|
from servers.redis.server import redis_service
|
|
|
|
servers: List[BaseService] = [
|
|
database_service,
|
|
redis_service,
|
|
]
|
|
|
|
@asynccontextmanager
|
|
async def servers_lifespan(app: FastAPI):
|
|
global servers
|
|
for server in servers:
|
|
await server.initialize()
|
|
|
|
@app.get("/health")
|
|
async def health_check():
|
|
health_status = {}
|
|
for server in servers:
|
|
health_status[server.service_name] = await server.check_health()
|
|
return health_status
|
|
|
|
yield
|
|
for server in servers:
|
|
await server.shutdown()
|
|
|