[add]: Database health check
This commit is contained in:
@@ -19,6 +19,8 @@ from flask_jwt_extended import (
|
|||||||
get_jwt_identity,
|
get_jwt_identity,
|
||||||
create_refresh_token,
|
create_refresh_token,
|
||||||
)
|
)
|
||||||
|
from sqlalchemy import text
|
||||||
|
from app.extensions import db
|
||||||
|
|
||||||
|
|
||||||
api = Blueprint("api", __name__)
|
api = Blueprint("api", __name__)
|
||||||
@@ -117,7 +119,24 @@ def notification_callback():
|
|||||||
# Health Check Endpoint
|
# Health Check Endpoint
|
||||||
@api.route("/health", methods=["GET"])
|
@api.route("/health", methods=["GET"])
|
||||||
def health_check():
|
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
|
# Authorize endpoint
|
||||||
|
|||||||
@@ -83,6 +83,10 @@
|
|||||||
"description": "Find out more",
|
"description": "Find out more",
|
||||||
"url": "https://www.simbrellang.net"
|
"url": "https://www.simbrellang.net"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Health",
|
||||||
|
"description": "System health check including DB status."
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
@@ -106,6 +110,38 @@
|
|||||||
},
|
},
|
||||||
"/Repayment": {
|
"/Repayment": {
|
||||||
"$ref": "swagger/paths/Repayment.json"
|
"$ref": "swagger/paths/Repayment.json"
|
||||||
|
},
|
||||||
|
"/health": {
|
||||||
|
"get": {
|
||||||
|
"tags": ["Health"],
|
||||||
|
"summary": "Health Check",
|
||||||
|
"description": "Returns service health information including DB connection status.",
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Health check successful",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"example": {
|
||||||
|
"status": "ok",
|
||||||
|
"db_status": "Connection Successful"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Health check failed",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"example": {
|
||||||
|
"status": "ok",
|
||||||
|
"db_status": "Connection Failed",
|
||||||
|
"error": "could not connect to server: Connection refused"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
|
|||||||
Reference in New Issue
Block a user