Skip to content

Commit

Permalink
Add retry to accounting export summary post
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwin1111 committed Oct 6, 2023
1 parent 5e3ef20 commit 93c6d56
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
12 changes: 12 additions & 0 deletions apps/fyle/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
8 changes: 4 additions & 4 deletions apps/fyle/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
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
from apps.fyle.models import Expense, ExpenseFilter, ExpenseGroup, ExpenseGroupSettings
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__)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 93c6d56

Please sign in to comment.