fixed restart error

This commit was merged in pull request #36.
This commit is contained in:
Chinenye Nmoh
2025-07-03 15:37:53 +01:00
parent 501d0f2703
commit 0000907698
3 changed files with 33 additions and 11 deletions
+1 -1
View File
@@ -18,4 +18,4 @@ ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
# 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"]
+31 -9
View File
@@ -16,6 +16,8 @@ from app.services.repayments_data import RepaymentsData
from app.services.salary import SalaryService
from app.enums.loan_status import LoanStatus
from decimal import Decimal, ROUND_HALF_UP
from requests.exceptions import SSLError, RequestException,Timeout
import sys
class SimbrellaClient:
@@ -222,6 +224,7 @@ class SimbrellaClient:
# InitiatedBy = REPAYMENT_DUE
return SimbrellaClient._collect_loan(data,"3")
@staticmethod
def _collect_loan(data, collectionMethod: str):
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)
t_id = ''.join(random.choices(string.ascii_uppercase, k=22))
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'],
"debtId": debtId,
"customerId": repayment_data['customerId'],
@@ -271,14 +274,17 @@ class SimbrellaClient:
try:
logger.info(f"Sending CollectLoan request............ {collect_loan_data}")
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:
RepaymentService.set_repay_result(
repayment_data['Id'],
'404',
'Collection Service url not found')
repayment_data['Id'],
'404',
'Collection Service url not found'
)
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()
logger.info(f"CollectLoan response: {result}")
@@ -316,7 +322,7 @@ class SimbrellaClient:
return ResponseHelper.error("Loan has no balance. Skipping.")
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)
logger.info(f"Updated loan: {updated_loan}")
except Exception as ex:
@@ -340,9 +346,25 @@ class SimbrellaClient:
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:
logger.exception("Failed to call CollectLoan endpoint, {e}")
return ResponseHelper.error("Failed to process salary list", status_code=500, error=str(e))
logger.exception(f"Unexpected error occurred while calling CollectLoan: {e}")
return ResponseHelper.error("Unexpected error while processing loan collection", status_code=500, error=str(e))
@staticmethod
+1 -1
View File
@@ -138,7 +138,7 @@ def salary_detect():
try:
process_salary_list()
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))
logger.info("Finished processing List")