Merge branch 'health_check' of DigiFi/digifi-BankToProductCore into master
This commit is contained in:
@@ -50,3 +50,20 @@ class EventServiceIntegration:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Direct Repayment API call failed: {str(e)}", exc_info=True)
|
logger.error(f"Direct Repayment API call failed: {str(e)}", exc_info=True)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def health_check():
|
||||||
|
"""
|
||||||
|
Health check for Events Service
|
||||||
|
"""
|
||||||
|
url = f"{EventServiceIntegration.EVENTS_SERVICE_BASE_URL}/health"
|
||||||
|
logger.info(f"Health Check URL: {url}")
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = httpx.get(url, timeout=5.0)
|
||||||
|
logger.info(f"Health Check Response: {response.text}")
|
||||||
|
return response
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Health Check API call failed: {str(e)}", exc_info=True)
|
||||||
|
raise
|
||||||
|
|||||||
+33
-10
@@ -1,3 +1,5 @@
|
|||||||
|
from sqlite3 import DatabaseError
|
||||||
|
from app.api.integrations.events_service import EventServiceIntegration
|
||||||
from flask import Blueprint, request, jsonify, send_from_directory
|
from flask import Blueprint, request, jsonify, send_from_directory
|
||||||
from app.api.services import (
|
from app.api.services import (
|
||||||
EligibilityCheckService,
|
EligibilityCheckService,
|
||||||
@@ -21,6 +23,7 @@ from flask_jwt_extended import (
|
|||||||
)
|
)
|
||||||
from sqlalchemy import text
|
from sqlalchemy import text
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
|
from app.config import settings
|
||||||
|
|
||||||
|
|
||||||
api = Blueprint("api", __name__)
|
api = Blueprint("api", __name__)
|
||||||
@@ -120,26 +123,46 @@ def notification_callback():
|
|||||||
@api.route("/health", methods=["GET"])
|
@api.route("/health", methods=["GET"])
|
||||||
def health_check():
|
def health_check():
|
||||||
|
|
||||||
|
|
||||||
response = {}
|
response = {}
|
||||||
db_status = "Connect Successful"
|
db_status = "Connection Successful"
|
||||||
error = None
|
events_service_status = "Connection Successful"
|
||||||
|
errors = []
|
||||||
status = "ok"
|
status = "ok"
|
||||||
|
|
||||||
|
# Check database connection
|
||||||
try:
|
try:
|
||||||
# Simple query to validate DB connection
|
|
||||||
db.session.execute(text("SELECT 1"))
|
db.session.execute(text("SELECT 1"))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
db_status = "Connection Failed"
|
db_status = "Connection Failed"
|
||||||
error = str(e)
|
errors.append(f"Database Error: {str(e)}")
|
||||||
status = "failed"
|
status = "failed"
|
||||||
|
|
||||||
response["status"] = status
|
|
||||||
response["db_status"] = db_status
|
|
||||||
if error:
|
|
||||||
response["error"] = error
|
|
||||||
|
|
||||||
return jsonify(response), 200 if db_status == "Connect Successful" else 500
|
# Check Events Service health
|
||||||
|
try:
|
||||||
|
events_service_response = EventServiceIntegration.health_check()
|
||||||
|
|
||||||
|
if events_service_response.status_code != 200:
|
||||||
|
events_service_status = "Connection Failed"
|
||||||
|
status = "failed"
|
||||||
|
errors.append(f"Events Service response: {events_service_response.text}")
|
||||||
|
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
events_service_status = "Connection Successful"
|
||||||
|
status = "failed"
|
||||||
|
errors.append(f"Events Service connection failed: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
|
response = {
|
||||||
|
"status": status,
|
||||||
|
"db_status": db_status,
|
||||||
|
"events_service_status": events_service_status,
|
||||||
|
"errors": errors or None
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return jsonify(response), 200 if status == "ok" else 500
|
||||||
|
|
||||||
|
|
||||||
# Authorize endpoint
|
# Authorize endpoint
|
||||||
|
|||||||
@@ -123,7 +123,9 @@
|
|||||||
"application/json": {
|
"application/json": {
|
||||||
"example": {
|
"example": {
|
||||||
"status": "ok",
|
"status": "ok",
|
||||||
"db_status": "Connection Successful"
|
"db_status": "Connection Successful",
|
||||||
|
"events_service_status": "healthy",
|
||||||
|
"error": []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,7 +137,8 @@
|
|||||||
"example": {
|
"example": {
|
||||||
"status": "ok",
|
"status": "ok",
|
||||||
"db_status": "Connection Failed",
|
"db_status": "Connection Failed",
|
||||||
"error": "could not connect to server: Connection refused"
|
"events_service_status": "unhealthy",
|
||||||
|
"error":["could not connect to server: Connection refused"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user