Skip to content

Commit

Permalink
feature(app):
Browse files Browse the repository at this point in the history
- add db close method
  • Loading branch information
MorvanZhou committed May 16, 2024
1 parent ca5e35c commit c342db7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/retk/models/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions src/retk/models/search_engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class BaseEngine(ABC):
async def init(self):
...

@abstractmethod
async def close(self):
...

@abstractmethod
async def drop(self):
...
Expand Down
3 changes: 3 additions & 0 deletions src/retk/models/search_engine/engine_es.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions src/retk/models/search_engine/engine_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c342db7

Please sign in to comment.