Silence lock manager model import warning.
This commit is contained in:
@@ -4,7 +4,7 @@ import logging
|
|||||||
|
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
|
||||||
from lock_manager import Lock, LockError
|
from lock_manager import LockError
|
||||||
from mayan.celery import app
|
from mayan.celery import app
|
||||||
|
|
||||||
from .literals import CHECKOUT_EXPIRATION_LOCK_EXPIRE
|
from .literals import CHECKOUT_EXPIRATION_LOCK_EXPIRE
|
||||||
@@ -17,12 +17,15 @@ def task_check_expired_check_outs():
|
|||||||
DocumentCheckout = apps.get_model(
|
DocumentCheckout = apps.get_model(
|
||||||
app_label='checkouts', model_name='DocumentCheckout'
|
app_label='checkouts', model_name='DocumentCheckout'
|
||||||
)
|
)
|
||||||
|
Lock = apps.get_model(
|
||||||
|
app_label='lock_manager', model_name='Lock'
|
||||||
|
)
|
||||||
|
|
||||||
logger.debug('executing...')
|
logger.debug('executing...')
|
||||||
lock_id = 'task_expired_check_outs'
|
lock_id = 'task_expired_check_outs'
|
||||||
try:
|
try:
|
||||||
logger.debug('trying to acquire lock: %s', lock_id)
|
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
|
name=lock_id, timeout=CHECKOUT_EXPIRATION_LOCK_EXPIRE
|
||||||
)
|
)
|
||||||
logger.debug('acquired lock: %s', lock_id)
|
logger.debug('acquired lock: %s', lock_id)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from django.apps import apps
|
|||||||
from django.db import OperationalError
|
from django.db import OperationalError
|
||||||
|
|
||||||
from mayan.celery import app
|
from mayan.celery import app
|
||||||
from lock_manager import Lock, LockError
|
from lock_manager import LockError
|
||||||
|
|
||||||
from .literals import RETRY_DELAY
|
from .literals import RETRY_DELAY
|
||||||
|
|
||||||
@@ -18,9 +18,12 @@ def task_delete_empty_index_nodes(self):
|
|||||||
IndexInstanceNode = apps.get_model(
|
IndexInstanceNode = apps.get_model(
|
||||||
app_label='document_indexing', model_name='IndexInstanceNode'
|
app_label='document_indexing', model_name='IndexInstanceNode'
|
||||||
)
|
)
|
||||||
|
Lock = apps.get_model(
|
||||||
|
app_label='lock_manager', model_name='Lock'
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rebuild_lock = Lock.acquire_lock(
|
rebuild_lock = Lock.objects.acquire_lock(
|
||||||
'document_indexing_task_do_rebuild_all_indexes'
|
'document_indexing_task_do_rebuild_all_indexes'
|
||||||
)
|
)
|
||||||
except LockError as exception:
|
except LockError as exception:
|
||||||
@@ -43,8 +46,12 @@ def task_index_document(self, document_id):
|
|||||||
app_label='document_indexing', model_name='IndexInstanceNode'
|
app_label='document_indexing', model_name='IndexInstanceNode'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Lock = apps.get_model(
|
||||||
|
app_label='lock_manager', model_name='Lock'
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
rebuild_lock = Lock.acquire_lock(
|
rebuild_lock = Lock.objects.acquire_lock(
|
||||||
'document_indexing_task_do_rebuild_all_indexes'
|
'document_indexing_task_do_rebuild_all_indexes'
|
||||||
)
|
)
|
||||||
except LockError as exception:
|
except LockError as exception:
|
||||||
@@ -52,7 +59,7 @@ def task_index_document(self, document_id):
|
|||||||
raise self.retry(exc=exception)
|
raise self.retry(exc=exception)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
lock = Lock.acquire_lock(
|
lock = Lock.objects.acquire_lock(
|
||||||
'document_indexing_task_update_index_document_%d' % document_id
|
'document_indexing_task_update_index_document_%d' % document_id
|
||||||
)
|
)
|
||||||
except LockError as exception:
|
except LockError as exception:
|
||||||
@@ -89,12 +96,16 @@ def task_do_rebuild_all_indexes(self):
|
|||||||
app_label='document_indexing', model_name='IndexInstanceNode'
|
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'):
|
if Lock.check_existing(name__startswith='document_indexing_task_update_index_document'):
|
||||||
# A document index update is happening, wait
|
# A document index update is happening, wait
|
||||||
raise self.retry()
|
raise self.retry()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lock = Lock.acquire_lock(
|
lock = Lock.objects.acquire_lock(
|
||||||
'document_indexing_task_do_rebuild_all_indexes'
|
'document_indexing_task_do_rebuild_all_indexes'
|
||||||
)
|
)
|
||||||
except LockError as exception:
|
except LockError as exception:
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from .exceptions import LockError # NOQA
|
from .exceptions import LockError # NOQA
|
||||||
from .models import Lock as LockModel
|
|
||||||
|
|
||||||
Lock = LockModel.objects
|
|
||||||
default_app_config = 'lock_manager.apps.LockManagerApp'
|
default_app_config = 'lock_manager.apps.LockManagerApp'
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import logging
|
|||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import OperationalError
|
from django.db import OperationalError
|
||||||
|
|
||||||
from documents.models import DocumentVersion
|
from documents.models import DocumentVersion
|
||||||
from lock_manager import Lock, LockError
|
from lock_manager import LockError
|
||||||
from mayan.celery import app
|
from mayan.celery import app
|
||||||
|
|
||||||
from .classes import TextExtractor
|
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)
|
@app.task(bind=True, default_retry_delay=DO_OCR_RETRY_DELAY, ignore_result=True)
|
||||||
def task_do_ocr(self, document_version_pk):
|
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
|
lock_id = 'task_do_ocr_doc_version-%d' % document_version_pk
|
||||||
try:
|
try:
|
||||||
logger.debug('trying to acquire lock: %s', lock_id)
|
logger.debug('trying to acquire lock: %s', lock_id)
|
||||||
# Acquire lock to avoid doing OCR on the same document version more than
|
# Acquire lock to avoid doing OCR on the same document version more than
|
||||||
# once concurrently
|
# 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)
|
logger.debug('acquired lock: %s', lock_id)
|
||||||
document_version = None
|
document_version = None
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user