Add plugable locking backend support. Add threadsafe file lock backend.

This commit is contained in:
Roberto Rosario
2016-11-13 03:50:09 -04:00
parent f5e3d5a8f2
commit 44531bd92a
12 changed files with 155 additions and 65 deletions

View File

@@ -10,6 +10,7 @@ from django.db import OperationalError
from documents.models import DocumentVersion
from lock_manager import LockError
from lock_manager.runtime import locking_backend
from mayan.celery import app
from .classes import TextExtractor
@@ -22,16 +23,12 @@ logger = logging.getLogger(__name__)
@app.task(bind=True, default_retry_delay=DO_OCR_RETRY_DELAY, ignore_result=True)
def task_do_ocr(self, document_version_pk):
Lock = apps.get_model(
app_label='lock_manager', model_name='Lock'
)
lock_id = 'task_do_ocr_doc_version-%d' % document_version_pk
try:
logger.debug('trying to acquire lock: %s', lock_id)
# Acquire lock to avoid doing OCR on the same document version more than
# once concurrently
lock = Lock.objects.acquire_lock(lock_id, LOCK_EXPIRE)
lock = locking_backend.acquire_lock(lock_id, LOCK_EXPIRE)
logger.debug('acquired lock: %s', lock_id)
document_version = None
try: