Move indexing retry amount to the literals.py module. Specify retry delay in the task decorator to reduce repetition.
This commit is contained in:
1
mayan/apps/document_indexing/literals.py
Normal file
1
mayan/apps/document_indexing/literals.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
RETRY_DELAY = 20 # TODO: convert this into a config option
|
||||||
@@ -6,19 +6,19 @@ from mayan.celery import app
|
|||||||
from documents.models import Document
|
from documents.models import Document
|
||||||
from lock_manager import Lock, LockError
|
from lock_manager import Lock, LockError
|
||||||
|
|
||||||
|
from .literals import RETRY_DELAY
|
||||||
from .models import IndexInstanceNode
|
from .models import IndexInstanceNode
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
RETRY_DELAY = 20 # TODO: convert this into a config option
|
|
||||||
|
|
||||||
|
|
||||||
@app.task(bind=True, ignore_result=True)
|
@app.task(bind=True, default_retry_delay=RETRY_DELAY, ignore_result=True)
|
||||||
def task_delete_empty_index_nodes(self):
|
def task_delete_empty_index_nodes(self):
|
||||||
try:
|
try:
|
||||||
rebuild_lock = Lock.acquire_lock('document_indexing_task_do_rebuild_all_indexes')
|
rebuild_lock = Lock.acquire_lock('document_indexing_task_do_rebuild_all_indexes')
|
||||||
except LockError as exception:
|
except LockError as exception:
|
||||||
# A rebuild is happening, retry later
|
# A rebuild is happening, retry later
|
||||||
raise self.retry(exc=exception, countdown=RETRY_DELAY)
|
raise self.retry(exc=exception)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
IndexInstanceNode.objects.delete_empty_index_nodes()
|
IndexInstanceNode.objects.delete_empty_index_nodes()
|
||||||
@@ -26,19 +26,19 @@ def task_delete_empty_index_nodes(self):
|
|||||||
rebuild_lock.release()
|
rebuild_lock.release()
|
||||||
|
|
||||||
|
|
||||||
@app.task(bind=True, ignore_result=True)
|
@app.task(bind=True, default_retry_delay=RETRY_DELAY, ignore_result=True)
|
||||||
def task_index_document(self, document_id):
|
def task_index_document(self, document_id):
|
||||||
try:
|
try:
|
||||||
rebuild_lock = Lock.acquire_lock('document_indexing_task_do_rebuild_all_indexes')
|
rebuild_lock = Lock.acquire_lock('document_indexing_task_do_rebuild_all_indexes')
|
||||||
except LockError as exception:
|
except LockError as exception:
|
||||||
# A rebuild is happening, retry later
|
# A rebuild is happening, retry later
|
||||||
raise self.retry(exc=exception, countdown=RETRY_DELAY)
|
raise self.retry(exc=exception)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
lock = Lock.acquire_lock('document_indexing_task_update_index_document_%d' % document_id)
|
lock = Lock.acquire_lock('document_indexing_task_update_index_document_%d' % document_id)
|
||||||
except LockError as exception:
|
except LockError as exception:
|
||||||
# This document is being reindexed by another task, retry later
|
# This document is being reindexed by another task, retry later
|
||||||
raise self.retry(exc=exception, countdown=RETRY_DELAY)
|
raise self.retry(exc=exception)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
document = Document.objects.get(pk=document_id)
|
document = Document.objects.get(pk=document_id)
|
||||||
@@ -53,17 +53,17 @@ def task_index_document(self, document_id):
|
|||||||
rebuild_lock.release()
|
rebuild_lock.release()
|
||||||
|
|
||||||
|
|
||||||
@app.task(bind=True, ignore_result=True)
|
@app.task(bind=True, default_retry_delay=RETRY_DELAY, ignore_result=True)
|
||||||
def task_do_rebuild_all_indexes(self):
|
def task_do_rebuild_all_indexes(self):
|
||||||
if Lock.filter(name__startswith='document_indexing_task_update_index_document'):
|
if Lock.filter(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(countdown=RETRY_DELAY)
|
raise self.retry()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lock = Lock.acquire_lock('document_indexing_task_do_rebuild_all_indexes')
|
lock = Lock.acquire_lock('document_indexing_task_do_rebuild_all_indexes')
|
||||||
except LockError as exception:
|
except LockError as exception:
|
||||||
# Another rebuild is happening, retry later
|
# Another rebuild is happening, retry later
|
||||||
raise self.retry(exc=exception, countdown=RETRY_DELAY)
|
raise self.retry(exc=exception)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
IndexInstanceNode.objects.rebuild_all_indexes()
|
IndexInstanceNode.objects.rebuild_all_indexes()
|
||||||
|
|||||||
Reference in New Issue
Block a user