included bank call to health check #48
@@ -57,6 +57,7 @@ class Config:
|
||||
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_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")
|
||||
|
||||
settings = Config()
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
from .kafka import KafkaIntegration
|
||||
from .simbrella import SimbrellaClient
|
||||
from .simbrella import SimbrellaClient
|
||||
from .bank_service import BankService
|
||||
@@ -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
|
||||
@@ -32,6 +32,7 @@ class SimbrellaClient:
|
||||
BANK_CALL_DISBURSE_LOAN_ENDPOINT = settings.BANK_CALL_DISBURSE_LOAN_ENDPOINT
|
||||
BANK_CALL_COLLECT_LOAN_ENDPOINT = settings.BANK_CALL_COLLECT_LOAN_ENDPOINT
|
||||
BANK_CALL_TRANSACTION_VERIFY = settings.BANK_CALL_TRANSACTION_VERIFY
|
||||
BANK_HEALTH_CHECK_ENDPOINT = settings.BANK_HEALTH_CHECK_ENDPOINT
|
||||
|
||||
@staticmethod
|
||||
def disburse_loan(data):
|
||||
@@ -399,4 +400,6 @@ class SimbrellaClient:
|
||||
|
||||
except Exception as e:
|
||||
logger.info(f"Failed to call Penal Charge endpoint: {e}")
|
||||
raise
|
||||
raise
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ from sqlalchemy import text
|
||||
from app.utils.auth import get_headers
|
||||
from app.config import settings
|
||||
from app.utils.logger import logger
|
||||
from app.integrations.bank_service import BankService
|
||||
|
||||
auth_bp = Blueprint("auth", __name__)
|
||||
|
||||
@@ -14,30 +15,60 @@ BASE_URL = settings.BANK_CALL_BASE_URL
|
||||
@auth_bp.route("/health", methods=["GET"])
|
||||
def health():
|
||||
logger.info("Health check endpoint called")
|
||||
errors = [] # collect all errors
|
||||
|
||||
try:
|
||||
# Detect database type
|
||||
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:
|
||||
query = text("SELECT 1 FROM dual")
|
||||
else: # Postgres, MySQL, SQLite, etc.
|
||||
else:
|
||||
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({
|
||||
"status": "success",
|
||||
"database": dialect,
|
||||
"message": "Database connection successful"
|
||||
"db_status": "connected",
|
||||
"bank_service_status": "operational",
|
||||
"message": "All systems operational"
|
||||
}), 200
|
||||
|
||||
except Exception as e:
|
||||
logger.exception("Unexpected error during health check")
|
||||
return jsonify({
|
||||
"status": "error",
|
||||
"message": str(e)
|
||||
"errors": [str(e)]
|
||||
}), 500
|
||||
|
||||
|
||||
|
||||
@auth_bp.route("/login", methods=["POST"])
|
||||
def login():
|
||||
data = request.get_json()
|
||||
|
||||
Reference in New Issue
Block a user