From 7451d1ade524b2417d8739ce446333bcd7859283 Mon Sep 17 00:00:00 2001 From: Hrishabh Tiwari <74908943+Hrishabh17@users.noreply.github.com> Date: Wed, 14 Feb 2024 16:53:48 +0530 Subject: [PATCH] Added RetryException handler and bumped the sdk versions (#567) --- apps/fyle/tasks.py | 11 ++++++++++- apps/mappings/exceptions.py | 10 +++++++++- requirements.txt | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/apps/fyle/tasks.py b/apps/fyle/tasks.py index a7bd19ab..4df3eda1 100644 --- a/apps/fyle/tasks.py +++ b/apps/fyle/tasks.py @@ -3,7 +3,10 @@ from typing import Dict, List from django.db import transaction -from fyle.platform.exceptions import InvalidTokenError as FyleInvalidTokenError +from fyle.platform.exceptions import ( + InvalidTokenError as FyleInvalidTokenError, + RetryException +) from fyle_integrations_platform_connector import PlatformConnector from apps.fyle.actions import create_generator_and_post_in_batches, mark_expenses_as_skipped @@ -148,6 +151,12 @@ def async_create_expense_groups(workspace_id: int, fund_source: List[str], task_ task_log.status = 'FAILED' task_log.save() + except RetryException: + logger.info('Fyle Retry Exception occured in workspace_id %s', workspace_id) + task_log.detail = {'message': 'Retrying task'} + task_log.status = 'FATAL' + task_log.save() + except Exception: handle_import_exception(task_log) diff --git a/apps/mappings/exceptions.py b/apps/mappings/exceptions.py index 3934a824..9e561704 100644 --- a/apps/mappings/exceptions.py +++ b/apps/mappings/exceptions.py @@ -1,7 +1,12 @@ import logging import traceback -from fyle.platform.exceptions import InternalServerError, InvalidTokenError, WrongParamsError +from fyle.platform.exceptions import ( + InternalServerError, + InvalidTokenError, + WrongParamsError, + RetryException +) from qbosdk.exceptions import InvalidTokenError as QBOInvalidTokenError from qbosdk.exceptions import WrongParamsError as QBOWrongParamsError @@ -29,6 +34,9 @@ def new_fn(workspace_id: int, *args): error['response'] = exception.response error['alert'] = True + except RetryException: + error['message'] = 'Retrying task' + except InternalServerError as exception: error['message'] = 'Internal server error while importing to Fyle' error['response'] = exception.__dict__ diff --git a/requirements.txt b/requirements.txt index 93b65556..d55957d0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,7 +21,7 @@ django-sendgrid-v5==1.2.0 enum34==1.1.10 future==0.18.2 fyle-accounting-mappings==1.26.1 -fyle-integrations-platform-connector==1.36.2 +fyle-integrations-platform-connector==1.36.3 fyle-rest-auth==1.6.0 flake8==4.0.1 gevent==23.9.1