Add healthcheck.
This commit is contained in:
@@ -10,6 +10,11 @@ services:
|
||||
STAN: ${STAN}
|
||||
whiteids: ${whiteids}
|
||||
rollback: ${rollback}
|
||||
healthcheck:
|
||||
test: [ "CMD-SHELL", "python3 -c 'import requests; r=requests.get(\"http://127.0.0.1:8813/healthz\"); exit(0 if r.status_code==200 else 1)'" ]
|
||||
interval: 30s
|
||||
timeout: 5s
|
||||
retries: 3
|
||||
|
||||
volumes:
|
||||
stan_data:
|
||||
|
||||
+21
-1
@@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
import requests
|
||||
import telebot
|
||||
from fastapi import FastAPI
|
||||
|
||||
@@ -9,7 +10,7 @@ from .config import TOKEN
|
||||
|
||||
logging.warning("[START] Webhook server")
|
||||
app = FastAPI(docs=None, redoc_url=None)
|
||||
|
||||
BOT_API_URL = f"https://api.telegram.org/bot{TOKEN}/getMe"
|
||||
|
||||
@app.post(f"/bot{TOKEN}/")
|
||||
async def webhook(update: dict):
|
||||
@@ -19,3 +20,22 @@ async def webhook(update: dict):
|
||||
asyncio.ensure_future(bot.process_new_updates([update]))
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
@app.get("/healthz")
|
||||
async def healthcheck():
|
||||
"""Проверка здоровья для Docker."""
|
||||
# Cам FastAPI
|
||||
result = {"status": "ok"}
|
||||
|
||||
# Telegram API
|
||||
try:
|
||||
resp = requests.get(BOT_API_URL)
|
||||
if resp.status_code != 200:
|
||||
result["telegram_api"] = f"error {resp.status_code}"
|
||||
else:
|
||||
result["telegram_api"] = "ok"
|
||||
except Exception as e:
|
||||
result["telegram_api"] = str(e)
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user