diff --git a/src/retk/models/client.py b/src/retk/models/client.py index 42bae8e..b6c7a99 100644 --- a/src/retk/models/client.py +++ b/src/retk/models/client.py @@ -94,6 +94,13 @@ async def init_search(self): await self.search.init() + async def close(self): + if self.search is not None: + await self.search.close() + if self.mongo is not None: + if isinstance(self.mongo, MongitaClientDisk): + await self.mongo.close() + async def drop(self): if self.search is not None: await self.search.drop() diff --git a/src/retk/models/search_engine/engine.py b/src/retk/models/search_engine/engine.py index f62f622..4f26204 100644 --- a/src/retk/models/search_engine/engine.py +++ b/src/retk/models/search_engine/engine.py @@ -58,6 +58,10 @@ class BaseEngine(ABC): async def init(self): ... + @abstractmethod + async def close(self): + ... + @abstractmethod async def drop(self): ... diff --git a/src/retk/models/search_engine/engine_es.py b/src/retk/models/search_engine/engine_es.py index 6e5ed04..fdbfa9f 100644 --- a/src/retk/models/search_engine/engine_es.py +++ b/src/retk/models/search_engine/engine_es.py @@ -204,6 +204,9 @@ async def reindex(self): self.index = new_index logger.debug(f"elasticsearch reindex finished, new index: {self.index}") + async def close(self): + await self.es.close() + async def drop(self): await self.connect() if self.index != "" and await self.es.indices.exists(index=self.index): diff --git a/src/retk/models/search_engine/engine_local.py b/src/retk/models/search_engine/engine_local.py index 295326f..1793a00 100644 --- a/src/retk/models/search_engine/engine_local.py +++ b/src/retk/models/search_engine/engine_local.py @@ -81,6 +81,9 @@ def create_schema(analyzer): else: self.ix = open_dir(self.index_path) + async def close(self): + self.ix.close() + async def drop(self): try: w = self.ix.writer()