diff --git a/app/api/integrations/events_service.py b/app/api/integrations/events_service.py index 744b3a1..bc9fa82 100644 --- a/app/api/integrations/events_service.py +++ b/app/api/integrations/events_service.py @@ -50,3 +50,20 @@ class EventServiceIntegration: except Exception as e: logger.error(f"Direct Repayment API call failed: {str(e)}", exc_info=True) 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 diff --git a/app/api/routes/routes.py b/app/api/routes/routes.py index 2acfe4e..2804012 100644 --- a/app/api/routes/routes.py +++ b/app/api/routes/routes.py @@ -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 app.api.services import ( EligibilityCheckService, @@ -21,6 +23,7 @@ from flask_jwt_extended import ( ) from sqlalchemy import text from app.extensions import db +from app.config import settings api = Blueprint("api", __name__) @@ -120,26 +123,46 @@ def notification_callback(): @api.route("/health", methods=["GET"]) def health_check(): - response = {} - db_status = "Connect Successful" - error = None + db_status = "Connection Successful" + events_service_status = "Connection Successful" + errors = [] status = "ok" + # Check database connection try: - # Simple query to validate DB connection db.session.execute(text("SELECT 1")) except Exception as e: db_status = "Connection Failed" - error = str(e) + errors.append(f"Database Error: {str(e)}") 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 diff --git a/app/swagger/digifi_swagger.json b/app/swagger/digifi_swagger.json index 26b0445..6e0f87c 100644 --- a/app/swagger/digifi_swagger.json +++ b/app/swagger/digifi_swagger.json @@ -123,7 +123,9 @@ "application/json": { "example": { "status": "ok", - "db_status": "Connection Successful" + "db_status": "Connection Successful", + "events_service_status": "healthy", + "error": [] } } } @@ -135,7 +137,8 @@ "example": { "status": "ok", "db_status": "Connection Failed", - "error": "could not connect to server: Connection refused" + "events_service_status": "unhealthy", + "error":["could not connect to server: Connection refused"] } } }