Workflows: Refactor workflow preview generation
Refactor the workflow preview generation to work as a background task API service. Solves GitLab issue #532. The image generation runs as an out of process task ensuring that the HTTP request is never compromised. A new task queue named "document_states_fast" was created. The settings WORKFLOWS_IMAGE_CACHE_TIME, WORKFLOWS_IMAGE_CACHE_STORAGE_BACKEND, WORKFLOWS_IMAGE_CACHE_STORAGE_BACKEND_ARGUMENTS we added. Images generated are stored by default under /mayan/media/workflows. The Dockerfile and deployment instructions are updated to include the new queue. Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -2,6 +2,7 @@ from __future__ import absolute_import, unicode_literals
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.views.decorators.cache import cache_control, patch_cache_control
|
||||
|
||||
from rest_framework import generics
|
||||
|
||||
@@ -24,6 +25,7 @@ from .serializers import (
|
||||
WritableWorkflowInstanceLogEntrySerializer, WritableWorkflowSerializer,
|
||||
WritableWorkflowTransitionSerializer
|
||||
)
|
||||
from .settings import settings_workflow_image_cache_time
|
||||
from .storages import storage_workflowimagecache
|
||||
from .tasks import task_generate_workflow_image
|
||||
|
||||
@@ -243,6 +245,7 @@ class APIWorkflowImageView(generics.RetrieveAPIView):
|
||||
def get_serializer_class(self):
|
||||
return None
|
||||
|
||||
@cache_control(private=True)
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
task = task_generate_workflow_image.apply_async(
|
||||
kwargs=dict(
|
||||
@@ -253,6 +256,11 @@ class APIWorkflowImageView(generics.RetrieveAPIView):
|
||||
cache_filename = task.get(timeout=WORKFLOW_IMAGE_TASK_TIMEOUT)
|
||||
with storage_workflowimagecache.open(cache_filename) as file_object:
|
||||
response = HttpResponse(file_object.read(), content_type='image')
|
||||
if '_hash' in request.GET:
|
||||
patch_cache_control(
|
||||
response,
|
||||
max_age=settings_workflow_image_cache_time.value
|
||||
)
|
||||
return response
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user