[add]: threading for Kafa integration
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user