[add]: Database health check

This commit is contained in:
VivianDee
2025-10-03 14:54:56 +01:00
parent f5cf4e5bdd
commit ab9330bb23
2 changed files with 56 additions and 1 deletions
+20 -1
View File
@@ -19,6 +19,8 @@ from flask_jwt_extended import (
get_jwt_identity,
create_refresh_token,
)
from sqlalchemy import text
from app.extensions import db
api = Blueprint("api", __name__)
@@ -117,7 +119,24 @@ def notification_callback():
# Health Check Endpoint
@api.route("/health", methods=["GET"])
def health_check():
return {"status": "ok"}, 200
response = {"status": "ok"}
db_status = "Connect Successful"
error = None
try:
# Simple query to validate DB connection
db.session.execute(text("SELECT 1"))
except Exception as e:
db_status = "Connection Failed"
error = str(e)
response["db_status"] = db_status
if error:
response["error"] = error
return jsonify(response), 200 if db_status == "Connect Successful" else 500
# Authorize endpoint