[add]: threading for Kafa integration

This commit is contained in:
VivianDee
2025-04-03 12:35:50 +01:00
parent b180f8411d
commit 79ac972841
6 changed files with 21 additions and 8 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ class EligibilityCheckService(BaseService):
)
if "error" in response or response.get("status") != 200:
return jsonify({"message": "RACCheck failed", "error": response.get("message", response)}), 400
return jsonify({"message": "RACCheck failed"}), 400
+12 -1
View File
@@ -6,6 +6,8 @@ from app.api.enums import TransactionType
from app.utils.logger import logger
from app.api.schemas.provide_loan import ProvideLoanSchema
from app.api.integrations import KafkaIntegration
from threading import Thread
class ProvideLoanService(BaseService):
TRANSACTION_TYPE = TransactionType.PROVIDE_LOAN
@@ -53,7 +55,10 @@ class ProvideLoanService(BaseService):
}
response = KafkaIntegration.send_loan_request(loan_data = response_data, request_id = request_id)
# KafkaIntegration.send_loan_request(loan_data = response_data, request_id = request_id)
# Call Kafka in a background thread
thread = Thread(target=ProvideLoanService.async_send_to_kafka, args=(response_data, request_id))
thread.start()
return response_data
@@ -78,3 +83,9 @@ class ProvideLoanService(BaseService):
"message": "Internal Server Error"
}) , 500
def async_send_to_kafka(loan_data, request_id):
KafkaIntegration.send_loan_request(loan_data = loan_data, request_id = request_id)
KafkaIntegration.flush()