Skip to content

Commit

Permalink
Fix the lifespan function of the StorageService
Browse files Browse the repository at this point in the history
  • Loading branch information
pk5ls20 committed Jul 3, 2024
1 parent abbc879 commit fa9b1c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 3 additions & 5 deletions app/Services/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
2 changes: 2 additions & 0 deletions scripts/local_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fa9b1c2

Please sign in to comment.