Silence lock manager model import warning.

This commit is contained in:
Roberto Rosario
2016-03-08 02:32:03 -04:00
parent 927c0bf657
commit ad328b2c3b
4 changed files with 28 additions and 11 deletions

View File

@@ -4,7 +4,7 @@ import logging
from django.apps import apps
from lock_manager import Lock, LockError
from lock_manager import LockError
from mayan.celery import app
from .literals import CHECKOUT_EXPIRATION_LOCK_EXPIRE
@@ -17,12 +17,15 @@ def task_check_expired_check_outs():
DocumentCheckout = apps.get_model(
app_label='checkouts', model_name='DocumentCheckout'
)
Lock = apps.get_model(
app_label='lock_manager', model_name='Lock'
)
logger.debug('executing...')
lock_id = 'task_expired_check_outs'
try:
logger.debug('trying to acquire lock: %s', lock_id)
lock = Lock.acquire_lock(
lock = Lock.objects.acquire_lock(
name=lock_id, timeout=CHECKOUT_EXPIRATION_LOCK_EXPIRE
)
logger.debug('acquired lock: %s', lock_id)

View File

@@ -6,7 +6,7 @@ from django.apps import apps
from django.db import OperationalError
from mayan.celery import app
from lock_manager import Lock, LockError
from lock_manager import LockError
from .literals import RETRY_DELAY
@@ -18,9 +18,12 @@ def task_delete_empty_index_nodes(self):
IndexInstanceNode = apps.get_model(
app_label='document_indexing', model_name='IndexInstanceNode'
)
Lock = apps.get_model(
app_label='lock_manager', model_name='Lock'
)
try:
rebuild_lock = Lock.acquire_lock(
rebuild_lock = Lock.objects.acquire_lock(
'document_indexing_task_do_rebuild_all_indexes'
)
except LockError as exception:
@@ -43,8 +46,12 @@ def task_index_document(self, document_id):
app_label='document_indexing', model_name='IndexInstanceNode'
)
Lock = apps.get_model(
app_label='lock_manager', model_name='Lock'
)
try:
rebuild_lock = Lock.acquire_lock(
rebuild_lock = Lock.objects.acquire_lock(
'document_indexing_task_do_rebuild_all_indexes'
)
except LockError as exception:
@@ -52,7 +59,7 @@ def task_index_document(self, document_id):
raise self.retry(exc=exception)
else:
try:
lock = Lock.acquire_lock(
lock = Lock.objects.acquire_lock(
'document_indexing_task_update_index_document_%d' % document_id
)
except LockError as exception:
@@ -89,12 +96,16 @@ def task_do_rebuild_all_indexes(self):
app_label='document_indexing', model_name='IndexInstanceNode'
)
Lock = apps.get_model(
app_label='lock_manager', model_name='Lock'
)
if Lock.check_existing(name__startswith='document_indexing_task_update_index_document'):
# A document index update is happening, wait
raise self.retry()
try:
lock = Lock.acquire_lock(
lock = Lock.objects.acquire_lock(
'document_indexing_task_do_rebuild_all_indexes'
)
except LockError as exception:

View File

@@ -1,7 +1,5 @@
from __future__ import unicode_literals
from .exceptions import LockError # NOQA
from .models import Lock as LockModel
Lock = LockModel.objects
default_app_config = 'lock_manager.apps.LockManagerApp'

View File

@@ -4,11 +4,12 @@ import logging
import sys
import traceback
from django.apps import apps
from django.conf import settings
from django.db import OperationalError
from documents.models import DocumentVersion
from lock_manager import Lock, LockError
from lock_manager import LockError
from mayan.celery import app
from .classes import TextExtractor
@@ -21,12 +22,16 @@ 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.acquire_lock(lock_id, LOCK_EXPIRE)
lock = Lock.objects.acquire_lock(lock_id, LOCK_EXPIRE)
logger.debug('acquired lock: %s', lock_id)
document_version = None
try: