The index is now recreated in case loading fails.

This commit is contained in:
jonaswinkler 2020-11-26 22:18:30 +01:00
parent 4bf0d834a0
commit b589b7a5dc

View File

@ -64,15 +64,18 @@ def get_schema():
def open_index(recreate=False): def open_index(recreate=False):
if exists_in(settings.INDEX_DIR) and not recreate: # TODO: this is not thread safe. If 2 instances try to create the index
return open_dir(settings.INDEX_DIR) # at the same time, this fails. This currently prevents parallel
else: # tests.
# TODO: this is not thread safe. If 2 instances try to create the index try:
# at the same time, this fails. This currently prevents parallel if exists_in(settings.INDEX_DIR) and not recreate:
# tests. return open_dir(settings.INDEX_DIR)
if not os.path.isdir(settings.INDEX_DIR): except Exception as e:
os.makedirs(settings.INDEX_DIR, exist_ok=True) logger.error(f"Error while opening the index: {e}, recreating.")
return create_in(settings.INDEX_DIR, get_schema())
if not os.path.isdir(settings.INDEX_DIR):
os.makedirs(settings.INDEX_DIR, exist_ok=True)
return create_in(settings.INDEX_DIR, get_schema())
def update_document(writer, doc): def update_document(writer, doc):