From c42d5c8170d76419b1bff5cab33b5b7290417aa5 Mon Sep 17 00:00:00 2001 From: Marnanel Thurman Date: Tue, 21 May 2019 19:10:40 +0100 Subject: [PATCH] Remove AsyncResultView because async tasks access the db directly now. --- django_kepi/views.py | 86 -------------------------------------------- 1 file changed, 86 deletions(-) diff --git a/django_kepi/views.py b/django_kepi/views.py index 6a160de..c0b193c 100644 --- a/django_kepi/views.py +++ b/django_kepi/views.py @@ -266,89 +266,3 @@ class InboxView(django.views.View): # We need to support GET (as a collection) # but we don't yet. -######################################## - -class AsyncResultView(django.views.View): - - def post(self, request, *args, **kwargs): - - uuid_passcode = request.GET['uuid'] - success = int(request.GET['success'])!=0 - - if success: - - if not request.body: - logger.warn('Batch notification had success==1 but no body') - return django.http.HttpResponseBadRequest() - - body = str(request.body, encoding='UTF-8') - - # Why not use request.POST? Because the batch process might - # reasonably use Content-Type: application/activity+json, - # which Django wouldn't recognise as proper JSON, so - # request.POST wouldn't get populated. - - # XXX we might want to check the Content-Type here - - else: - - if request.POST: - logger.warn('Batch notification had success==0 but supplied a body') - return django.http.HttpResponseBadRequest() - - body = None - - try: - message_need = get_object_or_404(QuarantinedMessageNeeds, id=uuid_passcode) - except ValidationError as e: - logger.warn('Invalid UUID supplied: %s', uuid_passcode) - raise e - except QuarantinedMessageNeeds.NotFound as e: - logger.warn('Batch notification for unknown UUID: %s', - uuid_passcode) - raise e - - if success: - logger.info('Batch processing has retrieved %s:', - message_need.needs_to_fetch) - logger.debug(' -- its contents are %s', body) - else: - logger.info('Batch processing has failed to retrieve %s:', - message_need.needs_to_fetch) - - if success and body is not None: - try: - fields = json.loads(body) - kepi_create(fields) - except json.decoder.JSONDecodeError: - fields = None - success = False - logger.warn('Body was not JSON. Treating as failure.') - - if success: - logger.debug(' -- trying to deploy all matching messages again') - else: - logger.debug(' -- deleting all messages which relied on it') - - for need in list(QuarantinedMessageNeeds.objects.filter( - needs_to_fetch = message_need.needs_to_fetch)): - - message = need.message - need.delete() - - if success: - logger.debug(' -- trying to deploy %s', str(need.message)) - message.deploy(retrying=True) - else: - logger.debug(' -- deleting %s', str(need.message)) - message.delete() - - logger.debug(' -- finished') - - return HttpResponse( - status = 200, - reason = 'All is well', - content = '', - content_type = 'text/plain', - ) -