Der Pi-Runner veröffentlicht develop nach tsumugu-dev und main nach tsumugu. Co-authored-by: Cursor <cursoragent@cursor.com>
43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
"""Tsumugu — schmales Startgerüst, damit der Pi-Deploy einen Health-Check hat."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
import psycopg2
|
|
from fastapi import FastAPI
|
|
from fastapi.responses import JSONResponse
|
|
|
|
app = FastAPI(title="Tsumugu", docs_url=None, redoc_url=None)
|
|
|
|
|
|
def _database_status() -> str:
|
|
try:
|
|
connection = psycopg2.connect(
|
|
host=os.environ.get("DB_HOST", "postgres"),
|
|
port=os.environ.get("DB_PORT", "5432"),
|
|
dbname=os.environ.get("DB_NAME", "tsumugu"),
|
|
user=os.environ.get("DB_USER", "tsumugu"),
|
|
password=os.environ.get("DB_PASSWORD", ""),
|
|
connect_timeout=3,
|
|
)
|
|
connection.close()
|
|
except Exception:
|
|
return "error"
|
|
return "ok"
|
|
|
|
|
|
@app.get("/api/health")
|
|
def api_health():
|
|
database = _database_status()
|
|
status = "ok" if database == "ok" else "degraded"
|
|
return JSONResponse(
|
|
status_code=200 if database == "ok" else 503,
|
|
content={
|
|
"status": status,
|
|
"app": "tsumugu",
|
|
"env": os.environ.get("TSUMUGU_ENV", "development"),
|
|
"db": database,
|
|
},
|
|
)
|