Update Document model to use background image conversion task
This commit is contained in:
@@ -24,6 +24,7 @@ from converter.api import (convert, get_page_count,
|
||||
from converter.exceptions import UnknownFileFormat
|
||||
from converter.literals import (DEFAULT_ZOOM_LEVEL, DEFAULT_ROTATION,
|
||||
DEFAULT_PAGE_NUMBER)
|
||||
from converter.tasks import task_convert
|
||||
from mimetype.api import get_mimetype
|
||||
|
||||
from .exceptions import NewDocumentVersionNotAllowed
|
||||
@@ -37,9 +38,8 @@ from .settings import (CACHE_PATH, CHECKSUM_FUNCTION, DISPLAY_SIZE,
|
||||
UUID_FUNCTION, ZOOM_MAX_LEVEL, ZOOM_MIN_LEVEL)
|
||||
from .utils import document_save_to_temp_dir
|
||||
|
||||
# document image cache name hash function
|
||||
HASH_FUNCTION = lambda x: hashlib.sha256(x).hexdigest()
|
||||
|
||||
CONVERTER_TASK_TIMEOUT = 2 # In seconds
|
||||
HASH_FUNCTION = lambda x: hashlib.sha256(x).hexdigest() # document image cache name hash function
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -134,7 +134,8 @@ class Document(models.Model):
|
||||
|
||||
logger.debug('image_cache_name: %s' % image_cache_name)
|
||||
|
||||
return convert(image_cache_name, cleanup_files=False, size=size, zoom=zoom, rotation=rotation)
|
||||
task = task_convert.delay(image_cache_name, cleanup_files=False, size=size, zoom=zoom, rotation=rotation)
|
||||
return task.get(timeout=CONVERTER_TASK_TIMEOUT)
|
||||
|
||||
def get_image(self, size=DISPLAY_SIZE, page=DEFAULT_PAGE_NUMBER, zoom=DEFAULT_ZOOM_LEVEL, rotation=DEFAULT_ROTATION, as_base64=False, version=None):
|
||||
if zoom < ZOOM_MIN_LEVEL:
|
||||
|
||||
Reference in New Issue
Block a user