move action to SimbrellaClient integration

This commit is contained in:
2025-04-11 16:11:45 +01:00
parent 1a39afb216
commit 5214594fab
5 changed files with 44 additions and 16 deletions
+2 -1
View File
@@ -2,4 +2,5 @@
__pycache__/
*/__pycache__/
.env
app.log
app.log
.idea/
+1
View File
@@ -1 +1,2 @@
from .kafka import KafkaIntegration
from .simbrella import SimbrellaClient
+2 -2
View File
@@ -3,7 +3,7 @@ import json
from app.utils.logger import logger
from app.config import settings
import requests
from app.routes.loan import disbursement as disbursement_endpoint
from app.integrations.simbrella import SimbrellaClient
class KafkaIntegration:
@@ -96,7 +96,7 @@ class KafkaIntegration:
logger.info(f"Calling disbursement endpoint with message: {message}")
try:
response = disbursement_endpoint(message)
response = SimbrellaClient.disbursement(message)
logger.info(
f"Successfully sent message to disbursement endpoint: {response.status_code}"
)
+26
View File
@@ -0,0 +1,26 @@
import requests
from app.config import settings
from app.utils.auth import get_headers
from app.utils.logger import logger
from flask import jsonify
class SimbrellaClient:
BASE_URL = settings.BANK_CALL_BASE_URL
@staticmethod
def disbursement(data):
api_url = f"{SimbrellaClient.BASE_URL}/Disbursement"
logger.info(f"Calling disbursement endpoint with data: {data}")
response = requests.post(
api_url,
json=data,
headers=get_headers()
)
logger.info(f"Disbursement response: {response.json()}")
return jsonify(response.json()), response.status_code
+13 -13
View File
@@ -6,19 +6,19 @@ from app.utils.logger import logger
app = create_app()
if __name__ != "__main__":
kafka = KafkaIntegration()
logger.info("Starting Kafka consumer...")
while True:
message = kafka.receive_disbursement_messages(
topic=settings.KAFKA_PAYMENT_TOPIC, timeout=settings.KAFKA_TIMEOUT
)
if message:
logger.info(f"Processed message: {message}")
else:
logger.info("No message received within timeout")
#
# kafka = KafkaIntegration()
#
# logger.info("Starting Kafka consumer...")
# while True:
# message = kafka.receive_disbursement_messages(
# topic=settings.KAFKA_PAYMENT_TOPIC, timeout=settings.KAFKA_TIMEOUT
# )
#
# if message:
# logger.info(f"Processed message: {message}")
# else:
# logger.info("No message received within timeout")
# Expose WSGI app instance for Gunicorn
wsgi_app = app