Skip to content

Commit

Permalink
fix: delegate sync dimensions tasks to workers (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
1 parent 87e45d3 commit 178d999
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 13 additions & 3 deletions apps/fyle/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
from rest_framework.views import status

from apps.exceptions import handle_view_exceptions
from apps.fyle.actions import exportable_expense_group, get_expense_field, refresh_fyle_dimension, sync_fyle_dimension
from apps.fyle.actions import exportable_expense_group, get_expense_field
from apps.fyle.helpers import ExpenseGroupSearchFilter
from apps.fyle.models import ExpenseGroup, ExpenseGroupSettings
from apps.fyle.queue import async_import_and_export_expenses
from apps.fyle.serializers import ExpenseFieldSerializer, ExpenseGroupSerializer, ExpenseGroupSettingsSerializer
from apps.fyle.tasks import async_create_expense_groups, get_task_log_and_fund_source
from apps.workspaces.models import FyleCredential, Workspace
from fyle_xero_api.utils import LookupFieldMixin

from django_filters.rest_framework import DjangoFilterBackend
from django_q.tasks import async_task


class ExpenseGroupView(LookupFieldMixin, generics.ListCreateAPIView):
Expand Down Expand Up @@ -73,7 +75,11 @@ def post(self, request, *args, **kwargs):
Sync Data From Fyle
"""

sync_fyle_dimension(workspace_id=kwargs["workspace_id"])
# Check for a valid workspace and fyle creds and respond with 400 if not found
Workspace.objects.get(id=kwargs['workspace_id'])
FyleCredential.objects.get(workspace_id=kwargs['workspace_id'])

async_task('apps.fyle.actions.sync_fyle_dimension', kwargs['workspace_id'])

return Response(status=status.HTTP_200_OK)

Expand All @@ -89,7 +95,11 @@ def post(self, request, *args, **kwargs):
Sync data from Fyle
"""

refresh_fyle_dimension(workspace_id=kwargs["workspace_id"])
# Check for a valid workspace and fyle creds and respond with 400 if not found
Workspace.objects.get(id=kwargs['workspace_id'])
FyleCredential.objects.get(workspace_id=kwargs['workspace_id'])

async_task('apps.fyle.actions.refresh_fyle_dimension', kwargs['workspace_id'])

return Response(status=status.HTTP_200_OK)

Expand Down
16 changes: 13 additions & 3 deletions apps/xero/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
from django.db.models import Q
from apps.workspaces.models import Workspace, XeroCredentials
from django_filters.rest_framework import DjangoFilterBackend
from django_q.tasks import async_task
from fyle_accounting_mappings.models import DestinationAttribute
from fyle_accounting_mappings.serializers import DestinationAttributeSerializer
from rest_framework import generics
from rest_framework.response import Response
from rest_framework.views import status

from apps.exceptions import handle_view_exceptions
from apps.xero.actions import get_xero_connector, refersh_xero_dimension, sync_dimensions, sync_tenant
from apps.xero.actions import get_xero_connector, sync_tenant
from apps.xero.serializers import XeroFieldSerializer
from fyle_xero_api.utils import LookupFieldMixin

Expand Down Expand Up @@ -82,7 +84,11 @@ def post(self, request, *args, **kwargs):
Sync Data From Xero
"""

sync_dimensions(workspace_id=self.kwargs["workspace_id"])
# Check for a valid workspace and fyle creds and respond with 400 if not found
Workspace.objects.get(id=kwargs['workspace_id'])
XeroCredentials.get_active_xero_credentials(kwargs['workspace_id'])

async_task('apps.xero.actions.sync_dimensions', kwargs['workspace_id'])

return Response(status=status.HTTP_200_OK)

Expand All @@ -98,7 +104,11 @@ def post(self, request, *args, **kwargs):
Sync data from Xero
"""

refersh_xero_dimension(workspace_id=self.kwargs["workspace_id"])
# Check for a valid workspace and fyle creds and respond with 400 if not found
Workspace.objects.get(id=kwargs['workspace_id'])
XeroCredentials.get_active_xero_credentials(kwargs['workspace_id'])

async_task('apps.xero.actions.refersh_xero_dimension', kwargs['workspace_id'])

return Response(status=status.HTTP_200_OK)

Expand Down

0 comments on commit 178d999

Please sign in to comment.