Добавлена ветка prod_prep
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
"""Healthcheck endpoint for monitoring."""
|
||||
import asyncio
|
||||
import json
|
||||
from pathlib import Path
|
||||
from aiohttp import web
|
||||
from app.logger import logger
|
||||
|
||||
routes = web.RouteTableDef()
|
||||
|
||||
|
||||
@routes.get("/health")
|
||||
async def health(request):
|
||||
"""Basic health check — returns bot status."""
|
||||
health_data = {
|
||||
"status": "ok",
|
||||
"service": "spa-telegram-bot",
|
||||
"timestamp": asyncio.get_event_loop().time(),
|
||||
}
|
||||
|
||||
# Check if data files exist
|
||||
data_dir = Path(__file__).resolve().parent.parent / "data"
|
||||
health_data["data_dir_exists"] = data_dir.exists()
|
||||
|
||||
return web.json_response(health_data, status=200)
|
||||
|
||||
|
||||
@routes.get("/health/ready")
|
||||
async def ready(request):
|
||||
"""Readiness check — can the bot accept requests?"""
|
||||
return web.json_response({"status": "ready"}, status=200)
|
||||
|
||||
|
||||
async def start_health_server(port: int = 8080):
|
||||
"""Start healthcheck HTTP server on given port."""
|
||||
app = web.Application()
|
||||
app.add_routes(routes)
|
||||
runner = web.AppRunner(app)
|
||||
await runner.setup()
|
||||
site = web.TCPSite(runner, "0.0.0.0", port)
|
||||
await site.start()
|
||||
logger.info("Healthcheck server started on port {port}", port=port)
|
||||
return runner
|
||||
Reference in New Issue
Block a user