Merge branch 'test' of DigiFi/digifi-EventManager into master

This commit is contained in:
2025-10-22 09:42:27 +00:00
committed by Gogs
5 changed files with 68 additions and 7 deletions
+1
View File
@@ -57,6 +57,7 @@ class Config:
BANK_CALL_DISBURSE_LOAN_ENDPOINT = os.getenv("BANK_CALL_DISBURSE_LOAN_ENDPOINT","/DisburseLoan") BANK_CALL_DISBURSE_LOAN_ENDPOINT = os.getenv("BANK_CALL_DISBURSE_LOAN_ENDPOINT","/DisburseLoan")
BANK_CALL_COLLECT_LOAN_ENDPOINT = os.getenv("BANK_CALL_COLLECT_LOAN_ENDPOINT","/CollectLoan") BANK_CALL_COLLECT_LOAN_ENDPOINT = os.getenv("BANK_CALL_COLLECT_LOAN_ENDPOINT","/CollectLoan")
BANK_CALL_TRANSACTION_VERIFY = os.getenv("BANK_CALL_TRANSACTION_VERIFY", "/TransactionVerify") BANK_CALL_TRANSACTION_VERIFY = os.getenv("BANK_CALL_TRANSACTION_VERIFY", "/TransactionVerify")
BANK_HEALTH_CHECK_ENDPOINT = os.getenv("BANK_HEALTH_CHECK_ENDPOINT", "/system-health-check")
TEST_NO = os.getenv("TEST_NO", "2347038224367") TEST_NO = os.getenv("TEST_NO", "2347038224367")
settings = Config() settings = Config()
+2 -1
View File
@@ -1,2 +1,3 @@
from .kafka import KafkaIntegration from .kafka import KafkaIntegration
from .simbrella import SimbrellaClient from .simbrella import SimbrellaClient
from .bank_service import BankService
+25
View File
@@ -0,0 +1,25 @@
import requests
from app.config import settings
from app.utils.auth import get_headers
from app.utils.logger import logger
class BankService:
BANK_CALL_BASE_URL = settings.BANK_CALL_BASE_URL
BANK_HEALTH_CHECK_ENDPOINT = settings.BANK_HEALTH_CHECK_ENDPOINT
BANK_CALL_APP_ID = settings.BANK_CALL_APP_ID
@staticmethod
def health_check():
api_url = f"{BankService.BANK_CALL_BASE_URL}{BankService.BANK_HEALTH_CHECK_ENDPOINT}"
logger.info(f"Calling Health Check endpoint: {api_url}")
try:
response = requests.get(api_url, timeout=5, headers=get_headers())
logger.info(f"Health Check response status code: {response.status_code}")
return response.json()
except Exception as e:
logger.error(f"Health Check API call failed: {str(e)}", exc_info=True)
raise
+4 -1
View File
@@ -32,6 +32,7 @@ class SimbrellaClient:
BANK_CALL_DISBURSE_LOAN_ENDPOINT = settings.BANK_CALL_DISBURSE_LOAN_ENDPOINT BANK_CALL_DISBURSE_LOAN_ENDPOINT = settings.BANK_CALL_DISBURSE_LOAN_ENDPOINT
BANK_CALL_COLLECT_LOAN_ENDPOINT = settings.BANK_CALL_COLLECT_LOAN_ENDPOINT BANK_CALL_COLLECT_LOAN_ENDPOINT = settings.BANK_CALL_COLLECT_LOAN_ENDPOINT
BANK_CALL_TRANSACTION_VERIFY = settings.BANK_CALL_TRANSACTION_VERIFY BANK_CALL_TRANSACTION_VERIFY = settings.BANK_CALL_TRANSACTION_VERIFY
BANK_HEALTH_CHECK_ENDPOINT = settings.BANK_HEALTH_CHECK_ENDPOINT
@staticmethod @staticmethod
def disburse_loan(data): def disburse_loan(data):
@@ -399,4 +400,6 @@ class SimbrellaClient:
except Exception as e: except Exception as e:
logger.info(f"Failed to call Penal Charge endpoint: {e}") logger.info(f"Failed to call Penal Charge endpoint: {e}")
raise raise
+36 -5
View File
@@ -5,6 +5,7 @@ from sqlalchemy import text
from app.utils.auth import get_headers from app.utils.auth import get_headers
from app.config import settings from app.config import settings
from app.utils.logger import logger from app.utils.logger import logger
from app.integrations.bank_service import BankService
auth_bp = Blueprint("auth", __name__) auth_bp = Blueprint("auth", __name__)
@@ -14,30 +15,60 @@ BASE_URL = settings.BANK_CALL_BASE_URL
@auth_bp.route("/health", methods=["GET"]) @auth_bp.route("/health", methods=["GET"])
def health(): def health():
logger.info("Health check endpoint called") logger.info("Health check endpoint called")
errors = [] # collect all errors
try: try:
# Detect database type # Detect database type
dialect = db.engine.dialect.name.lower() dialect = db.engine.dialect.name.lower()
logger.info(f"the database dialect {dialect}") logger.info(f"Database dialect detected: {dialect}")
# Build correct query based on DB type
if "oracle" in dialect: if "oracle" in dialect:
query = text("SELECT 1 FROM dual") query = text("SELECT 1 FROM dual")
else: # Postgres, MySQL, SQLite, etc. else:
query = text("SELECT 1") query = text("SELECT 1")
db.session.execute(query) # Test database connection
try:
db.session.execute(query)
logger.info("Database connection successful.")
except Exception as db_err:
logger.error(f"Database connection failed: {str(db_err)}")
errors.append(f"Database connection failed: {str(db_err)}")
# Check Bank Service health
try:
bank_response = BankService.health_check()
logger.info(f"Bank Service health check response: {bank_response}")
except Exception as bank_err:
logger.error(f"Bank Service health check failed: {str(bank_err)}")
errors.append(f"Bank Service health check failed: {str(bank_err)}")
# Build final response
if errors:
return jsonify({
"status": "error",
"database": dialect,
"errors": errors
}), 500
return jsonify({ return jsonify({
"status": "success", "status": "success",
"database": dialect, "database": dialect,
"message": "Database connection successful" "db_status": "connected",
"bank_service_status": "operational",
"message": "All systems operational"
}), 200 }), 200
except Exception as e: except Exception as e:
logger.exception("Unexpected error during health check")
return jsonify({ return jsonify({
"status": "error", "status": "error",
"message": str(e) "errors": [str(e)]
}), 500 }), 500
@auth_bp.route("/login", methods=["POST"]) @auth_bp.route("/login", methods=["POST"])
def login(): def login():
data = request.get_json() data = request.get_json()