From 99c4f2ccfb8b26fde69e1f707178d60f51ef970f Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 5 Apr 2018 19:31:55 -0400 Subject: [PATCH] Use the document image generation task to create the images for the OCR. Signed-off-by: Roberto Rosario --- mayan/apps/ocr/managers.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mayan/apps/ocr/managers.py b/mayan/apps/ocr/managers.py index 4008b3282d..fb547a3648 100644 --- a/mayan/apps/ocr/managers.py +++ b/mayan/apps/ocr/managers.py @@ -8,7 +8,9 @@ from django.apps import apps from django.conf import settings from django.db import models -from documents.storages import documentimagecache_storage +from documents.storages import storage_documentimagecache +from documents.literals import DOCUMENT_IMAGE_TASK_TIMEOUT +from documents.tasks import task_generate_document_page_image from .events import event_ocr_document_version_finish from .runtime import ocr_backend @@ -28,10 +30,15 @@ class DocumentPageOCRContentManager(models.Manager): app_label='ocr', model_name='DocumentPageOCRContent' ) - # TODO: Call task and wait - cache_filename = document_page.generate_image() + task = task_generate_document_page_image.apply_async( + kwargs=dict( + document_page_id=document_page.pk + ) + ) - with documentimagecache_storage.open(cache_filename) as file_object: + cache_filename = task.get(timeout=DOCUMENT_IMAGE_TASK_TIMEOUT) + + with storage_documentimagecache.open(cache_filename) as file_object: document_page_content, created = DocumentPageOCRContent.objects.get_or_create( document_page=document_page )