Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Prefix for ES everywhere #218

Merged
merged 5 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -211,9 +209,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