Skip to content

Commit

Permalink
Merge pull request #883 from onaio/read-replicas
Browse files Browse the repository at this point in the history
do not always use primary but retry on primary if not found in first call
  • Loading branch information
ukanga authored Jan 19, 2017
2 parents c5eebb1 + 31365bb commit 4b82dcb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions onadata/apps/api/viewsets/xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
from rest_framework.exceptions import ParseError
from rest_framework.filters import DjangoFilterBackend

from onadata.apps.api import tasks
from onadata.apps.logger.xform_instance_parser import XLSFormError
from onadata.apps.main.views import get_enketo_preview_url
from onadata.apps.api import tasks
from onadata.apps.viewer.models.export import Export
from onadata.libs import filters, authentication
from onadata.libs.mixins.anonymous_user_public_forms_mixin import (
AnonymousUserPublicFormsMixin)
Expand Down Expand Up @@ -607,7 +608,6 @@ def delete_async(self, request, *args, **kwargs):
return Response(data=resp, status=resp_code)

@detail_route(methods=['GET'])
@use_master
def export_async(self, request, *args, **kwargs):
job_uuid = request.query_params.get('job_uuid')
export_type = request.query_params.get('format')
Expand All @@ -627,7 +627,12 @@ def export_async(self, request, *args, **kwargs):
})

if job_uuid:
resp = get_async_response(job_uuid, request, xform)
try:
resp = get_async_response(job_uuid, request, xform)
except Export.DoesNotExist:
# if this does not exist retry it against the primary
with use_master:
resp = get_async_response(job_uuid, request, xform)
else:
resp = process_async_export(request, xform, export_type, options)

Expand Down

0 comments on commit 4b82dcb

Please sign in to comment.