From 93c6d5657e1cb468d3c69bc21c18367efd221d46 Mon Sep 17 00:00:00 2001 From: ashwin1111 Date: Fri, 6 Oct 2023 10:59:02 +0530 Subject: [PATCH] Add retry to accounting export summary post --- apps/fyle/actions.py | 12 ++++++++++++ apps/fyle/tasks.py | 8 ++++---- requirements.txt | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/fyle/actions.py b/apps/fyle/actions.py index 0d6f30e3..69577e1d 100644 --- a/apps/fyle/actions.py +++ b/apps/fyle/actions.py @@ -5,6 +5,8 @@ from django.db.models import Q from fyle_integrations_platform_connector import PlatformConnector +from fyle.platform.internals.decorators import retry +from fyle.platform.exceptions import InternalServerError from fyle_accounting_mappings.models import ExpenseAttribute from apps.fyle.constants import DEFAULT_FYLE_CONDITIONS @@ -224,3 +226,13 @@ def update_complete_expenses(exported_expenses: List[Expense], url: str) -> None ) __bulk_update_expenses(expense_to_be_updated) + +@retry(n=3, backoff=1, exceptions=InternalServerError) +def bulk_post_accounting_export_summary(platform: PlatformConnector, payload: List[dict]): + """ + Bulk post accounting export summary with retry of 3 times and backoff of 1 second which handles InternalServerError + :param platform: Platform connector object + :param payload: Payload + :return: None + """ + platform.expenses.post_bulk_accounting_export_summary(payload) diff --git a/apps/fyle/tasks.py b/apps/fyle/tasks.py index fb156fbe..0bea9030 100644 --- a/apps/fyle/tasks.py +++ b/apps/fyle/tasks.py @@ -4,7 +4,7 @@ from typing import List from django.db import transaction -from fyle.platform.exceptions import InvalidTokenError as FyleInvalidTokenError, InternalServerError +from fyle.platform.exceptions import InvalidTokenError as FyleInvalidTokenError, RetryException from fyle_integrations_platform_connector import PlatformConnector from apps.fyle.helpers import construct_expense_filter_query @@ -12,7 +12,7 @@ from apps.tasks.models import TaskLog from apps.workspaces.models import FyleCredential, Workspace, WorkspaceGeneralSettings -from .actions import mark_expenses_as_skipped, mark_accounting_export_summary_as_synced +from .actions import mark_expenses_as_skipped, mark_accounting_export_summary_as_synced, bulk_post_accounting_export_summary from .queue import async_post_accounting_export_summary logger = logging.getLogger(__name__) @@ -192,9 +192,9 @@ def post_accounting_export_summary(org_id: str, workspace_id: int) -> None: if payload: try: - platform.expenses.post_bulk_accounting_export_summary(payload) + bulk_post_accounting_export_summary(platform, payload) mark_accounting_export_summary_as_synced(paginated_expenses) - except InternalServerError: + except RetryException: logger.error( 'Internal server error while posting accounting export summary to Fyle workspace_id: %s', workspace_id diff --git a/requirements.txt b/requirements.txt index 9f60e62e..e8bfb12a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,7 +20,7 @@ djangorestframework==3.11.2 django-sendgrid-v5==1.2.0 enum34==1.1.10 future==0.18.2 -fyle==0.33.0 +fyle==0.33.1 fyle-accounting-mappings==1.26.1 fyle-integrations-platform-connector==1.33.0 fyle-rest-auth==1.5.0