1
0

[add]: Events Service health check

This commit is contained in:
VivianDee
2025-10-06 18:22:49 +01:00
parent 06b266c3a7
commit 244f648974
3 changed files with 55 additions and 12 deletions
+17
View File
@@ -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
+33 -10
View File
@@ -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
+5 -2
View File
@@ -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"]
}
}
}