[add]: health endpoint
This commit was merged in pull request #22.
This commit is contained in:
@@ -23,6 +23,9 @@ from flask_jwt_extended import (
|
||||
get_jwt_identity,
|
||||
create_refresh_token,
|
||||
)
|
||||
from sqlalchemy import text
|
||||
from app.extensions import db
|
||||
from app.config import settings
|
||||
|
||||
api = Blueprint('api', __name__)
|
||||
|
||||
@@ -266,4 +269,45 @@ def get_all_offers():
|
||||
# }
|
||||
# # logger.info(f"Get charges request received with filters: {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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user