From f86be42dd0616c147927b105dee2b99ad930cccb Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Wed, 22 Oct 2014 18:21:40 -0400 Subject: [PATCH] Issue #57, conver the document image queue maintenance view into a celery task --- mayan/apps/documents/tasks.py | 9 +++++++++ mayan/apps/documents/views.py | 9 +++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/mayan/apps/documents/tasks.py b/mayan/apps/documents/tasks.py index 179ed23826..128f9705f4 100644 --- a/mayan/apps/documents/tasks.py +++ b/mayan/apps/documents/tasks.py @@ -11,3 +11,12 @@ logger = logging.getLogger(__name__) def task_get_document_image(document_id, *args, **kwargs): document = Document.objects.get(pk=document_id) return document.get_image(*args, **kwargs) + + +@app.task +def task_clear_image_cache(): + # TODO: Error logging + #try: + Document.clear_image_cache() + # except Exception as exception: + # messages.error(request, _(u'Error clearing document image cache; %s') % exception) diff --git a/mayan/apps/documents/views.py b/mayan/apps/documents/views.py index cb4c9576e3..1c54408039 100644 --- a/mayan/apps/documents/views.py +++ b/mayan/apps/documents/views.py @@ -50,7 +50,7 @@ from .permissions import (PERMISSION_DOCUMENT_PROPERTIES_EDIT, from .runtime import storage_backend from .settings import (PREVIEW_SIZE, RECENT_COUNT, ROTATION_STEP, ZOOM_PERCENT_STEP, ZOOM_MAX_LEVEL, ZOOM_MIN_LEVEL) -from .tasks import task_get_document_image +from .tasks import task_clear_image_cache, task_get_document_image logger = logging.getLogger(__name__) @@ -1041,11 +1041,8 @@ def document_clear_image_cache(request): previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', reverse(settings.LOGIN_REDIRECT_URL)))) if request.method == 'POST': - try: - Document.clear_image_cache() - messages.success(request, _(u'Document image cache cleared successfully')) - except Exception as exception: - messages.error(request, _(u'Error clearing document image cache; %s') % exception) + task_clear_image_cache.apply_async(queue='tools') + messages.success(request, _(u'Document image cache clearing queued successfully.')) return HttpResponseRedirect(previous)