Merge branch 'bank-simbrella-calls' into vivian-update-01
This commit was merged in pull request #4.
This commit is contained in:
@@ -1 +1,2 @@
|
||||
from .simbrella import SimbrellaClient
|
||||
from .simbrella import SimbrellaIntegration
|
||||
from .kafka import KafkaIntegration
|
||||
@@ -21,23 +21,26 @@ class KafkaIntegration:
|
||||
"""Kafka producer"""
|
||||
if not KafkaIntegration._producer:
|
||||
KafkaIntegration._producer = Producer(KafkaIntegration._config)
|
||||
|
||||
logger.info(
|
||||
f"Connected to Kafka broker at {KafkaIntegration._config['bootstrap.servers']}"
|
||||
)
|
||||
|
||||
return KafkaIntegration._producer
|
||||
|
||||
|
||||
@staticmethod
|
||||
def delivery_report(err, msg):
|
||||
"""Called once for each message produced"""
|
||||
if err is not None:
|
||||
logger.error(f"Message delivery failed: {err}")
|
||||
raise RuntimeError(f"Message delivery failed: {err}")
|
||||
|
||||
logger.error(f'Message delivery failed: {err}')
|
||||
raise RuntimeError(f"Message delivery failed: {err}")
|
||||
|
||||
else:
|
||||
logger.debug(
|
||||
f"Message delivered to {msg.topic()} [{msg.partition()}] @ offset {msg.offset()}"
|
||||
)
|
||||
logger.debug(f'Message delivered to {msg.topic()} [{msg.partition()}] @ offset {msg.offset()}')
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def send_loan_request(loan_data, request_id):
|
||||
@@ -59,6 +62,7 @@ class KafkaIntegration:
|
||||
key=str(request_id),
|
||||
value=json.dumps(loan_data).encode("utf-8"),
|
||||
callback=KafkaIntegration.delivery_report,
|
||||
|
||||
)
|
||||
|
||||
producer.poll(0)
|
||||
|
||||
@@ -2,7 +2,7 @@ import requests
|
||||
from app.utils.logger import logger
|
||||
from app.config import settings
|
||||
|
||||
class SimbrellaClient:
|
||||
class SimbrellaIntegration:
|
||||
BASE_URL = settings.SIMBRELLA_BASE_URL
|
||||
|
||||
@staticmethod
|
||||
@@ -10,7 +10,7 @@ class SimbrellaClient:
|
||||
"""
|
||||
Calls the RACCheck endpoit
|
||||
"""
|
||||
url = f"{SimbrellaClient.BASE_URL}/RACCheck"
|
||||
url = f"{SimbrellaIntegration.BASE_URL}/RACCheck"
|
||||
|
||||
payload = {
|
||||
"customerId": customer_id,
|
||||
@@ -37,10 +37,9 @@ class SimbrellaClient:
|
||||
response = requests.post(url, json=payload, timeout=10)
|
||||
|
||||
# Raise an error for non-200 responses
|
||||
# response.raise_for_status()
|
||||
|
||||
response.raise_for_status()
|
||||
|
||||
return response.json()
|
||||
except requests.exceptions.RequestException as err:
|
||||
logger.error(f"RACCheck API call failed: {str(err)}", exc_info=True)
|
||||
return {"error": "RACCheck API error", "details": str(err)}
|
||||
return {"error": "RACCheck API error"}
|
||||
|
||||
Reference in New Issue
Block a user