Skip to content

Commit

Permalink
Use Prefix for ES everywhere (#218)
Browse files Browse the repository at this point in the history
* refactor: rename config_handler

* fix: add es6 mapping repo

* refactor: factor out ES6mappingRepo

* fix: fix es6 prefix

* style: after black
  • Loading branch information
kod-kristoff authored Dec 22, 2022
1 parent 5b93207 commit 9470926
Show file tree
Hide file tree
Showing 9 changed files with 407 additions and 1,488 deletions.
8 changes: 3 additions & 5 deletions karp/cliapp/subapps/entries_subapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,11 @@ def validate_entries(
),
):
typer.echo(f"reading from {path or 'stdin'} ...", err=True)
err_output = None

if not output and path:
output = Path(f"{path}.v6.jsonl")

if not err_output and output:
err_output = Path(f"{output}.errors.jsonl")
err_output = Path(f"{output}.errors.jsonl")

if config_path and resource_id_raw:
typer.echo("You can't provide both '--resource_id' and '--config/-c'", err=True)
Expand Down Expand Up @@ -210,9 +208,9 @@ def validate_entries(
)
if error_counter.counter > 0:
error_code = 130
print(
typer.echo(
f'{error_counter.counter} entries failed validation, see "{err_output}"',
file=sys.stderr,
err=True,
)

if error_code:
Expand Down
17 changes: 16 additions & 1 deletion karp/search_infrastructure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
NoOpIndexUnitOfWork,
Es6IndexUnitOfWork,
)
from karp.search_infrastructure.elasticsearch6 import Es6MappingRepository


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -116,21 +117,35 @@ class Es6SearchIndexMod(injector.Module):
def __init__(self, index_prefix: Optional[str] = None) -> None:
self._index_prefix = index_prefix or ""

@injector.provider
@injector.singleton
def es6_mapping_repo(
self,
es: elasticsearch.Elasticsearch,
) -> Es6MappingRepository:
return Es6MappingRepository(es=es)

@injector.provider
def es6_search_service(
self,
es: elasticsearch.Elasticsearch,
mapping_repo: Es6MappingRepository,
) -> SearchService:
return Es6SearchService(es=es)
return Es6SearchService(
es=es,
mapping_repo=mapping_repo,
)

@injector.provider
def es6_index_uow(
self,
es: elasticsearch.Elasticsearch,
event_bus: EventBus,
mapping_repo: Es6MappingRepository,
) -> IndexUnitOfWork:
return Es6IndexUnitOfWork(
es=es,
event_bus=event_bus,
index_prefix=self._index_prefix,
mapping_repo=mapping_repo,
)
19 changes: 4 additions & 15 deletions karp/search_infrastructure/elasticsearch6/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
# from elasticsearch import Elasticsearch # pyre-ignore
from karp.search_infrastructure.elasticsearch6.es_mapping_repo import (
Es6MappingRepository,
)

# from karp.application import ctx
# from karp.infrastructure.elasticsearch6.es6_search_service import Es6SearchService


# def init_es(host):
# print("Setting up ES with host={}".format(host))
# es = Elasticsearch(
# hosts=host,
# sniff_on_start=True,
# sniff_on_connection_fail=True,
# sniffer_timeout=60,
# sniff_timeout=10,
# )
# search_service = Es6SearchService(es)
# ctx.search_service = search_service
__all__ = ["Es6MappingRepository"]
Loading

0 comments on commit 9470926

Please sign in to comment.