28 lines
808 B
Python
28 lines
808 B
Python
|
|
import logging
|
||
|
|
|
||
|
|
from aiohttp import web
|
||
|
|
|
||
|
|
logger = logging.getLogger("vision")
|
||
|
|
|
||
|
|
|
||
|
|
async def start_health_server(port: int, host: str = "0.0.0.0"):
|
||
|
|
"""Demarre un mini serveur HTTP expose par le conteneur Docker.
|
||
|
|
|
||
|
|
Le runner de deploiement interroge /health pour valider le demarrage
|
||
|
|
(health check post-deploy, comme Kuby).
|
||
|
|
"""
|
||
|
|
|
||
|
|
async def health(_request: web.Request) -> web.Response:
|
||
|
|
return web.Response(text='{"status":"ok"}', content_type="application/json")
|
||
|
|
|
||
|
|
app = web.Application()
|
||
|
|
app.router.add_get("/health", health)
|
||
|
|
app.router.add_get("/api/health", health)
|
||
|
|
|
||
|
|
runner = web.AppRunner(app)
|
||
|
|
await runner.setup()
|
||
|
|
site = web.TCPSite(runner, host, port)
|
||
|
|
await site.start()
|
||
|
|
logger.info("Health server demarre sur %s:%s", host, port)
|
||
|
|
return runner
|