refactor result processing

This commit is contained in:
Matthias 2021-10-20 22:06:32 +02:00
parent 1b72dfeae6
commit a03c560914
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -57,8 +57,10 @@ class WebhookView(CsrfExemptMixin, APIView):
if self.run_async: if self.run_async:
async_task(self._process_payload, message.id) async_task(self._process_payload, message.id)
else: else:
message.worked_on = self.webhook.process_payload(message, payload, headers) self.process_result(
message.save() self.webhook.process_payload(message, payload, headers),
message,
)
# return results # return results
data = self.webhook.get_result(payload, headers, request) data = self.webhook.get_result(payload, headers, request)
@ -66,9 +68,17 @@ class WebhookView(CsrfExemptMixin, APIView):
def _process_payload(self, message_id): def _process_payload(self, message_id):
message = WebhookMessage.objects.get(message_id=message_id) message = WebhookMessage.objects.get(message_id=message_id)
process_result = self.webhook.process_payload(message, message.body, message.header) self.process_result(
message.worked_on = process_result self.webhook.process_payload(message, message.body, message.header),
message.save() message,
)
def process_result(self, result, message):
if result:
message.worked_on = result
message.save()
else:
message.delete()
def _escalate_object(self, obj): def _escalate_object(self, obj):
classes = inheritors(obj.__class__) classes = inheritors(obj.__class__)