Skip to content

Commit

Permalink
Move elasticsearch utils
Browse files Browse the repository at this point in the history
  • Loading branch information
matti-lamppu committed Oct 2, 2024
1 parent 62f916a commit fc7a117
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 27 deletions.
File renamed without changes.
7 changes: 4 additions & 3 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,8 @@ def SEARCH_SETTINGS(cls):
"never_auto_sync": [],
# if true, then indexes must have mapping files
"strict_validation": False,
"mappings_dir": "elastic_django",
# Path to the elasticsearch mapping files
"mappings_dir": str(Common.BASE_DIR / "config" / "elasticsearch"),
},
}

Expand Down Expand Up @@ -655,7 +656,7 @@ class Local(Common, overrides_from=LocalMixin):
@property
def SEARCH_SETTINGS(cls):
search_settings = super().SEARCH_SETTINGS
search_settings["settings"]["mappings_dir"] = str(Common.BASE_DIR / "elastic_django")
search_settings["settings"]["mappings_dir"] = str(Common.BASE_DIR / "config" / "elasticsearch")
return search_settings

# --- Misc settings-----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -820,7 +821,7 @@ class AutomatedTests(EmptyDefaults, Common, dotenv_path=None, overrides_from=Aut
@property
def SEARCH_SETTINGS(cls):
search_settings = super().SEARCH_SETTINGS
search_settings["settings"]["mappings_dir"] = str(Common.BASE_DIR / "elastic_django")
search_settings["settings"]["mappings_dir"] = str(Common.BASE_DIR / "config" / "elasticsearch")
search_settings["settings"]["auto_sync"] = False
return search_settings

Expand Down
Empty file removed elastic_django/__init__.py
Empty file.
Empty file.
22 changes: 0 additions & 22 deletions elastic_django/reservation_units/tasks.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_utils/test_reservation_unit_query_builder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from elastic_django.reservation_units.query_builder import build_elastic_query_str
from utils.elasticsearch import build_elastic_query_str


def test_build_elastic_query_str__one_search_word():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from graphene_django_extensions import ModelFilterSet
from graphene_django_extensions.filters import EnumMultipleChoiceFilter, IntMultipleChoiceFilter

from elastic_django.reservation_units.query_builder import build_elastic_query_str
from tilavarauspalvelu.enums import ReservationKind, ReservationUnitPublishingState, ReservationUnitReservationState
from tilavarauspalvelu.models import ReservationUnit
from tilavarauspalvelu.models.reservation_unit.queryset import ReservationUnitQuerySet
from utils.date_utils import local_datetime
from utils.elasticsearch import build_elastic_query_str
from utils.utils import log_text_search

if TYPE_CHECKING:
Expand Down
19 changes: 19 additions & 0 deletions tilavarauspalvelu/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from easy_thumbnails.exceptions import InvalidImageFormatError
from elasticsearch_django.index import create_index, delete_index, update_index
from lookup_property import L

from config.celery import app
Expand Down Expand Up @@ -800,3 +801,21 @@ def log_to_sentry_if_suspicious(request_log: RequestLog, duration_ms: int) -> No
"num_of_queries": num_of_queries,
}
SentryLogger.log_message(msg, details=details, level="warning")


@app.task(name="Update ReservationUnit Elastic index")
def update_reservation_unit_elastic_index() -> None:
index = next(iter(settings.SEARCH_SETTINGS["indexes"].keys()))
update_index(index)


@app.task(name="Create ReservationUnit Elastic index")
def create_reservation_unit_elastic_index() -> None:
index = next(iter(settings.SEARCH_SETTINGS["indexes"].keys()))
create_index(index)


@app.task(name="Delete ReservationUnit Elastic index")
def delete_reservation_unit_elastic_index() -> None:
index = next(iter(settings.SEARCH_SETTINGS["indexes"].keys()))
delete_index(index)
File renamed without changes.

0 comments on commit fc7a117

Please sign in to comment.