From fa9b1c2ad090ccbc8dda0a409fae27f15b1ced8d Mon Sep 17 00:00:00 2001 From: pk5ls20 Date: Wed, 3 Jul 2024 09:06:21 +0800 Subject: [PATCH] Fix the lifespan function of the StorageService --- app/Services/storage/__init__.py | 8 +++----- scripts/local_indexing.py | 2 ++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Services/storage/__init__.py b/app/Services/storage/__init__.py index 7bbfedc..44f864d 100644 --- a/app/Services/storage/__init__.py +++ b/app/Services/storage/__init__.py @@ -6,11 +6,10 @@ class StorageService(LifespanService): def __init__(self): - self.local_storage = LocalStorage() self.active_storage = None match config.storage.method: case StorageMode.LOCAL: - self.active_storage = self.local_storage + self.active_storage = LocalStorage() case StorageMode.S3: self.active_storage = S3Storage() case StorageMode.DISABLED: @@ -20,8 +19,7 @@ def __init__(self): f"Available methods: local, s3") async def on_load(self): - await self.active_storage.on_load() if self.active_storage else await self.local_storage.on_load() + await self.active_storage.on_load() async def on_exit(self): - await self.active_storage.on_exit() if self.active_storage else await self.local_storage.on_exit() - + await self.active_storage.on_exit() diff --git a/scripts/local_indexing.py b/scripts/local_indexing.py index 9c38422..247b012 100644 --- a/scripts/local_indexing.py +++ b/scripts/local_indexing.py @@ -8,6 +8,7 @@ from app.Models.img_data import ImageData from app.Services.provider import ServiceProvider +from app.config import config, StorageMode from app.util.generate_uuid import generate_uuid from .local_utility import fetch_path_uuid_list @@ -50,6 +51,7 @@ async def copy_and_index_batch(file_path_list: list[tuple[Path, str]]): @logger.catch() async def main(args): global services + config.storage.method = StorageMode.LOCAL # ensure to use LocalStorage services = ServiceProvider() await services.onload() root = Path(args.local_index_target_dir)