Merge branch 'add_health' of DigiFi/FirstCore into master
This commit is contained in:
@@ -23,6 +23,9 @@ 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
|
||||||
|
from app.config import settings
|
||||||
|
|
||||||
api = Blueprint('api', __name__)
|
api = Blueprint('api', __name__)
|
||||||
|
|
||||||
@@ -266,4 +269,45 @@ def get_all_offers():
|
|||||||
# }
|
# }
|
||||||
# # logger.info(f"Get charges request received with filters: {filters}")
|
# # logger.info(f"Get charges request received with filters: {filters}")
|
||||||
# response = ChargeService.get_all_charges(filters)
|
# response = ChargeService.get_all_charges(filters)
|
||||||
# return jsonify(response)
|
# return jsonify(response)
|
||||||
|
|
||||||
|
|
||||||
|
# Health Check Endpoint
|
||||||
|
@api.route("/health", methods=["GET"])
|
||||||
|
def health_check():
|
||||||
|
SQLALCHEMY_DATABASE_URI = settings.SQLALCHEMY_DATABASE_URI
|
||||||
|
response = {}
|
||||||
|
db_status = "Connection Successful"
|
||||||
|
errors = []
|
||||||
|
status = "ok"
|
||||||
|
|
||||||
|
|
||||||
|
# Extract the database URI
|
||||||
|
try:
|
||||||
|
db_uri = db.engine.url.render_as_string(hide_password=False)
|
||||||
|
db_uri = db_uri
|
||||||
|
except Exception as e:
|
||||||
|
db_uri = "Unavailable"
|
||||||
|
errors.append(f"Database URI Error: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Check database connection
|
||||||
|
try:
|
||||||
|
logger.info(f"Database Health == : {SQLALCHEMY_DATABASE_URI}")
|
||||||
|
db.session.execute(text("SELECT 1"))
|
||||||
|
except Exception as e:
|
||||||
|
db_status = "Connection Failed"
|
||||||
|
errors.append(f"Database Error: {str(e)}")
|
||||||
|
status = "failed"
|
||||||
|
|
||||||
|
response = {
|
||||||
|
"status": status,
|
||||||
|
"db_status": db_status,
|
||||||
|
"db_uri": db_uri,
|
||||||
|
"errors": errors or None
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return jsonify(response), 200 if status == "ok" else 500
|
||||||
|
|
||||||
|
|||||||
@@ -103,6 +103,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": {
|
||||||
@@ -138,6 +142,39 @@
|
|||||||
},
|
},
|
||||||
"/transaction-offers": {
|
"/transaction-offers": {
|
||||||
"$ref": "../swagger/paths/TransactionOffers.json"
|
"$ref": "../swagger/paths/TransactionOffers.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",
|
||||||
|
"error": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"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