This commit is contained in:
Untone 2024-02-29 13:55:44 +03:00
parent 14c2750d92
commit 0ea4e596d2

View File

@ -99,16 +99,16 @@ class SearchService:
if self.client: if self.client:
if self.lock.acquire(blocking=False): if self.lock.acquire(blocking=False):
try: try:
logger.debug(f'Recreating index: {self.index_name}') logger.debug(f'Создается индекс: {self.index_name}')
self.delete_index() self.delete_index()
self.check_index() self.check_index()
logger.debug(f'Index {self.index_name} recreated') logger.debug(f'Индексс {self.index_name} создан')
except Exception as e: except Exception as e:
logger.debug(f'Error recreating index: {str(e)}') logger.debug(f'Ошибка создания индекса: {str(e)}')
finally: finally:
self.lock.release() self.lock.release()
else: else:
logger.debug('Unable to acquire lock to recreate index') logger.error('Не получается создать индекс')
def put_mapping(self): def put_mapping(self):
if self.client: if self.client:
@ -129,19 +129,18 @@ class SearchService:
self.recreate_index() self.recreate_index()
def recreate_index(self): def recreate_index(self):
if self.lock.acquire(blocking=False):
try:
thread = threading.Thread(target=self._recreate_index) thread = threading.Thread(target=self._recreate_index)
thread.start() thread.start()
thread.join()
def _recreate_index(self):
if self.lock.acquire(blocking=False):
try:
self.delete_index()
self.check_index()
finally: finally:
self.lock.release() self.lock.release()
else: else:
logger.debug(' cant reindex at the moment') logger.debug(' не удалось проиндексировать')
def _recreate_index(self):
self.delete_index()
self.check_index()
def index(self, shout): def index(self, shout):
if self.client: if self.client: