Merge branch 'test' of DigiFi/digifi-EventManager into master
This commit is contained in:
+1
-1
@@ -18,4 +18,4 @@ ENV FLASK_APP=app.py
|
|||||||
ENV FLASK_RUN_HOST=0.0.0.0
|
ENV FLASK_RUN_HOST=0.0.0.0
|
||||||
|
|
||||||
# Run the application
|
# Run the application
|
||||||
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "wsgi:wsgi_app"]
|
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:5000", "--timeout", "120", "wsgi:wsgi_app"]
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ from app.services.repayments_data import RepaymentsData
|
|||||||
from app.services.salary import SalaryService
|
from app.services.salary import SalaryService
|
||||||
from app.enums.loan_status import LoanStatus
|
from app.enums.loan_status import LoanStatus
|
||||||
from decimal import Decimal, ROUND_HALF_UP
|
from decimal import Decimal, ROUND_HALF_UP
|
||||||
|
from requests.exceptions import SSLError, RequestException,Timeout
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class SimbrellaClient:
|
class SimbrellaClient:
|
||||||
@@ -222,6 +224,7 @@ class SimbrellaClient:
|
|||||||
# InitiatedBy = REPAYMENT_DUE
|
# InitiatedBy = REPAYMENT_DUE
|
||||||
return SimbrellaClient._collect_loan(data,"3")
|
return SimbrellaClient._collect_loan(data,"3")
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _collect_loan(data, collectionMethod: str):
|
def _collect_loan(data, collectionMethod: str):
|
||||||
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}{SimbrellaClient.BANK_CALL_COLLECT_LOAN_ENDPOINT}"
|
api_url = f"{SimbrellaClient.BANK_CALL_BASE_URL}{SimbrellaClient.BANK_CALL_COLLECT_LOAN_ENDPOINT}"
|
||||||
@@ -253,7 +256,7 @@ class SimbrellaClient:
|
|||||||
debtId = str(loan_data.get('debtId', "")).strip().zfill(6)
|
debtId = str(loan_data.get('debtId', "")).strip().zfill(6)
|
||||||
t_id = ''.join(random.choices(string.ascii_uppercase, k=22))
|
t_id = ''.join(random.choices(string.ascii_uppercase, k=22))
|
||||||
collect_loan_data = {
|
collect_loan_data = {
|
||||||
"transactionId": t_id, #made this a random string to avoid duplicate transaction with transactionId from Charles
|
"transactionId": t_id,
|
||||||
"fbnTransactionId": loan_data['transactionId'],
|
"fbnTransactionId": loan_data['transactionId'],
|
||||||
"debtId": debtId,
|
"debtId": debtId,
|
||||||
"customerId": repayment_data['customerId'],
|
"customerId": repayment_data['customerId'],
|
||||||
@@ -271,14 +274,17 @@ class SimbrellaClient:
|
|||||||
try:
|
try:
|
||||||
logger.info(f"Sending CollectLoan request............ {collect_loan_data}")
|
logger.info(f"Sending CollectLoan request............ {collect_loan_data}")
|
||||||
response = requests.post(api_url, json=collect_loan_data, timeout=30, headers=get_headers())
|
response = requests.post(api_url, json=collect_loan_data, timeout=30, headers=get_headers())
|
||||||
logger.info(f"respnse structure {response}")
|
|
||||||
|
logger.info(f"HTTP response object: {response}")
|
||||||
|
|
||||||
if response.status_code == 404:
|
if response.status_code == 404:
|
||||||
RepaymentService.set_repay_result(
|
RepaymentService.set_repay_result(
|
||||||
repayment_data['Id'],
|
repayment_data['Id'],
|
||||||
'404',
|
'404',
|
||||||
'Collection Service url not found')
|
'Collection Service url not found'
|
||||||
|
)
|
||||||
logger.error("Received 404 from external service")
|
logger.error("Received 404 from external service")
|
||||||
return ResponseHelper.error("Collection Service url not found", status_code=404)
|
return ResponseHelper.error("Collection Service URL not found", status_code=404)
|
||||||
|
|
||||||
result = response.json()
|
result = response.json()
|
||||||
logger.info(f"CollectLoan response: {result}")
|
logger.info(f"CollectLoan response: {result}")
|
||||||
@@ -316,7 +322,7 @@ class SimbrellaClient:
|
|||||||
return ResponseHelper.error("Loan has no balance. Skipping.")
|
return ResponseHelper.error("Loan has no balance. Skipping.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logger.info(f"Updating loan balance for loan ID {loan_data} with amount collected: {amount_collected}")
|
logger.info(f"Updating loan balance for loan ID {loan_data['debtId']} with amount collected: {amount_collected}")
|
||||||
updated_loan = LoanService.update_loan_balance(int(loan_data['debtId']), amount_collected)
|
updated_loan = LoanService.update_loan_balance(int(loan_data['debtId']), amount_collected)
|
||||||
logger.info(f"Updated loan: {updated_loan}")
|
logger.info(f"Updated loan: {updated_loan}")
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
@@ -340,9 +346,25 @@ class SimbrellaClient:
|
|||||||
|
|
||||||
return ResponseHelper.success(result, "Successful")
|
return ResponseHelper.success(result, "Successful")
|
||||||
|
|
||||||
|
except SSLError as ssl_err:
|
||||||
|
logger.exception(f"SSL error while calling Simbrella endpoint: {ssl_err}")
|
||||||
|
return ResponseHelper.error("SSL handshake failed with Simbrella", status_code=502, error=str(ssl_err))
|
||||||
|
|
||||||
|
except Timeout as timeout_err:
|
||||||
|
logger.exception(f"Timeout while calling Simbrella: {timeout_err}")
|
||||||
|
return ResponseHelper.error("Connection to Simbrella timed out", status_code=504, error=str(timeout_err))
|
||||||
|
|
||||||
|
except RequestException as req_err:
|
||||||
|
logger.exception(f"RequestException while calling Simbrella: {req_err}")
|
||||||
|
return ResponseHelper.error("Connection to Simbrella failed", status_code=503, error=str(req_err))
|
||||||
|
|
||||||
|
except SystemExit as sys_exit:
|
||||||
|
logger.error(f"SystemExit was triggered: {sys_exit}")
|
||||||
|
return ResponseHelper.error("Unexpected shutdown detected", status_code=500, error=str(sys_exit))
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception("Failed to call CollectLoan endpoint, {e}")
|
logger.exception(f"Unexpected error occurred while calling CollectLoan: {e}")
|
||||||
return ResponseHelper.error("Failed to process salary list", status_code=500, error=str(e))
|
return ResponseHelper.error("Unexpected error while processing loan collection", status_code=500, error=str(e))
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ def salary_detect():
|
|||||||
try:
|
try:
|
||||||
process_salary_list()
|
process_salary_list()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception("Unhandled error occurred while processing salary list")
|
logger.exception("Unhandled error occurred while processing salary list {e}")
|
||||||
return ResponseHelper.error("Failed to process salary list", status_code=500, error=str(e))
|
return ResponseHelper.error("Failed to process salary list", status_code=500, error=str(e))
|
||||||
|
|
||||||
logger.info("Finished processing List")
|
logger.info("Finished processing List")
|
||||||
|
|||||||
Reference in New Issue
Block a user