<s> from __future__ import unicode_literals <EOL> import logging <EOL> from django . db import OperationalError <EOL> from mayan . celery import app <EOL> from documents . models import Document <EOL> from lock_manager import Lock , LockError <EOL> from . literals import RETRY_DELAY <EOL> from . models import IndexInstanceNode <EOL> logger = logging . getLogger ( __name__ ) <EOL> @ app . task ( bind = True , default_retry_delay = RETRY_DELAY , max_retries = None , ignore_result = True ) <EOL> def task_delete_empty_index_nodes ( self ) : <EOL> try : <EOL> rebuild_lock = Lock . acquire_lock ( <EOL> '<STR_LIT>' <EOL> ) <EOL> except LockError as exception : <EOL> raise self . retry ( exc = exception ) <EOL> else : <EOL> try : <EOL> IndexInstanceNode . objects . delete_empty_index_nodes ( ) <EOL> finally : <EOL> rebuild_lock . release ( ) <EOL> @ app . task ( bind = True , default_retry_delay = RETRY_DELAY , max_retries = None , ignore_result = True ) <EOL> def task_index_document ( self , document_id ) : <EOL> try : <EOL> rebuild_lock = Lock . acquire_lock ( <EOL> '<STR_LIT>' <EOL> ) <EOL> except LockError as exception : <EOL> raise self . retry ( exc = exception ) <EOL> else : <EOL> try : <EOL> lock = Lock . acquire_lock ( <EOL> '<STR_LIT>' % document_id <EOL> ) <EOL> except LockError as exception : <EOL> raise self . retry ( exc = exception ) <EOL> else : <EOL> try : <EOL> document = Document . objects . get ( pk = document_id ) <EOL> except Document . DoesNotExist : <EOL> pass <EOL> else : <EOL> try : <EOL> IndexInstanceNode . objects . index_document ( document ) <EOL> except OperationalError as exception : <EOL> logger . warning ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , document , exception <EOL> ) <EOL> lock . release ( ) <EOL> raise self . retry ( exc = exception ) <EOL> else : <EOL> lock . release ( ) <EOL> finally : <EOL> lock . release ( ) <EOL> finally : <EOL> rebuild_lock . release ( ) <EOL> @ app . task ( bind = True , default_retry_delay = RETRY_DELAY , ignore_result = True ) <EOL> def task_do_rebuild_all_indexes ( self ) : <EOL> if Lock . check_existing ( name__startswith = '<STR_LIT>' ) : <EOL> raise self . retry ( ) <EOL> try : <EOL> lock = Lock . acquire_lock ( <EOL> '<STR_LIT>' <EOL> ) <EOL> except LockError as exception : <EOL> raise self . retry ( exc = exception ) <EOL> else : <EOL> try : <EOL> IndexInstanceNode . objects . rebuild_all_indexes ( ) <EOL> finally : <EOL> lock . release ( ) </s>
