Skip to content

Commit

Permalink
add an option to immediately cancel the indexer if a specific index a…
Browse files Browse the repository at this point in the history
…lready exists
  • Loading branch information
pudo committed Oct 8, 2023
1 parent 95bccfc commit d1d03d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
16 changes: 14 additions & 2 deletions yente/search/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ async def index_entities(es: AsyncElasticsearch, dataset: Dataset, force: bool)
)
dataset_prefix = f"{settings.ENTITY_INDEX}-{dataset.name}-"
next_index = f"{dataset_prefix}{version}"
exists = await es.indices.exists_alias(name=settings.ENTITY_INDEX, index=next_index)
if settings.INDEX_EXISTS_ABORT:
exists = await es.indices.exists(index=next_index)
else:
exists = await es.indices.exists_alias(
name=settings.ENTITY_INDEX,
index=next_index,
)
if exists.body and not force:
log.info("Index is up to date.", index=next_index)
return False
Expand Down Expand Up @@ -134,7 +140,13 @@ async def index_entities(es: AsyncElasticsearch, dataset: Dataset, force: bool)
errors=errors,
entities_url=dataset.entities_url,
)
await es.indices.delete(index=next_index)
if settings.INDEX_EXISTS_ABORT:
is_linked = await es.indices.exists_alias(
name=settings.ENTITY_INDEX,
index=next_index,
)
if not is_linked.body:
await es.indices.delete(index=next_index)
return False

await es.indices.refresh(index=next_index)
Expand Down
1 change: 1 addition & 0 deletions yente/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def env_str(name: str, default: Optional[str] = None) -> Optional[str]:
ES_SHARDS = int(env_str("YENTE_ELASTICSEARCH_SHARDS") or "1")
ENTITY_INDEX = f"{ES_INDEX}-entities"
INDEX_VERSION = env_str("YENTE_INDEX_VERSION", "008")
INDEX_EXISTS_ABORT = as_bool(env_str("YENTE_INDEX_EXISTS_ABORT") or "false")

# Log output can be formatted as JSON:
LOG_JSON = as_bool(env_str("YENTE_LOG_JSON", "false"))
Expand Down

0 comments on commit d1d03d5

Please sign in to comment.