Compare commits
5 Commits
task_3
...
add_health
| Author | SHA1 | Date | |
|---|---|---|---|
| f4bc554396 | |||
| 4a697f14c8 | |||
| e5df8d92d3 | |||
| 3f59ed7da3 | |||
| 0957c2ea37 |
+12
-5
@@ -19,11 +19,18 @@ APP_PORT=4700
|
||||
#DATABASE_PORT=5432
|
||||
#DATABASE_NAME=firstadvancedev
|
||||
|
||||
DATABASE_USER=firstadvance
|
||||
DATABASE_PASSWORD=FirstAdvance!
|
||||
DATABASE_HOST=dev-data.simbrellang.net
|
||||
DATABASE_PORT=10532
|
||||
DATABASE_NAME=firstadvancedev
|
||||
DATABASE_USER=system
|
||||
DATABASE_PASSWORD=FIRSTADV_PASS
|
||||
DATABASE_HOST=10.10.33.65
|
||||
DATABASE_PORT=1521
|
||||
DATABASE_SID=FREE
|
||||
|
||||
|
||||
# DATABASE_USER=firstadvance
|
||||
# DATABASE_PASSWORD=FirstAdvance!
|
||||
# DATABASE_HOST=dev-data.simbrellang.net
|
||||
# DATABASE_PORT=10532
|
||||
# DATABASE_NAME=firstadvancedev
|
||||
|
||||
|
||||
#Events if Needed
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
+6
-1
@@ -19,8 +19,13 @@ class Config:
|
||||
DATABASE_HOST = os.environ.get("DATABASE_HOST")
|
||||
DATABASE_PORT = os.environ.get("DATABASE_PORT", 10532)
|
||||
DATABASE_NAME = os.environ.get("DATABASE_NAME")
|
||||
DATABASE_SID = os.environ.get("DATABASE_SID", "FREE")
|
||||
DNS = f"(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={DATABASE_HOST})(PORT={DATABASE_PORT}))(CONNECT_DATA=(SID={DATABASE_SID})))"
|
||||
|
||||
|
||||
# SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{DATABASE_USER}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}"
|
||||
SQLALCHEMY_DATABASE_URI = (f"oracle+oracledb://{DATABASE_USER}:{DATABASE_PASSWORD}@{DNS}")
|
||||
|
||||
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{DATABASE_USER}:{DATABASE_PASSWORD}@{DATABASE_HOST}:{DATABASE_PORT}/{DATABASE_NAME}"
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS = False
|
||||
SIMBRELLA_BASE_URL = os.getenv("SIMBRELLA_BASE_URL", "http://127.0.0.1:6337")
|
||||
|
||||
|
||||
@@ -103,6 +103,10 @@
|
||||
"description": "Find out more",
|
||||
"url": "https://www.simbrellang.net"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Health",
|
||||
"description": "System health check including DB status."
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
@@ -138,6 +142,39 @@
|
||||
},
|
||||
"/transaction-offers": {
|
||||
"$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": {
|
||||
|
||||
@@ -6,6 +6,7 @@ flask-sqlalchemy
|
||||
flask-migrate
|
||||
psycopg2-binary
|
||||
alembic
|
||||
oracledb
|
||||
|
||||
# Schema for validations
|
||||
Flask-Marshmallow==0.15.0
|
||||
|
||||
Reference in New Issue
Block a user