Stop trying to use the non-working DI of fastapi

This commit is contained in:
Zoe Roux 2025-05-14 00:46:33 +02:00
parent a821b97286
commit 75bc5a7d70
No known key found for this signature in database
4 changed files with 13 additions and 6 deletions

View File

@ -23,6 +23,7 @@ async def init_pool():
global pool global pool
pool = p pool = p
yield yield
pool = None # type: ignore
@asynccontextmanager @asynccontextmanager

View File

@ -1,3 +1,4 @@
from contextlib import asynccontextmanager
import os import os
import re import re
from logging import getLogger from logging import getLogger
@ -16,6 +17,7 @@ from .requests import Request, RequestCreator
logger = getLogger(__name__) logger = getLogger(__name__)
@asynccontextmanager
async def create_scanner(): async def create_scanner():
async with get_db() as db: async with get_db() as db:
yield FsScanner(KyooClient(), RequestCreator(db)) yield FsScanner(KyooClient(), RequestCreator(db))

View File

@ -36,12 +36,12 @@ class RequestCreator:
await self._database.executemany( await self._database.executemany(
""" """
insert into scanner.requests(kind, title, year, external_id, videos) insert into scanner.requests(kind, title, year, external_id, videos)
values (%(kind)s, %(title) s, %(year)s, %(external_id)s, %(videos)s) values ($1, $2, $3, $4, $5)
on conflict (kind, title, year) on conflict (kind, title, year)
do update set do update set
videos = videos || excluded.videos videos = videos || excluded.videos
""", """,
TypeAdapter(list[Request]).dump_python(requests), [[x.kind, x.title, x.year, x.external_id, x.videos] for x in requests],
) )
_ = await self._database.execute("notify scanner.requests") _ = await self._database.execute("notify scanner.requests")

View File

@ -1,8 +1,8 @@
from typing import Annotated from typing import Annotated
from fastapi import APIRouter, BackgroundTasks, Depends, Security from fastapi import APIRouter, BackgroundTasks, Security
from ..fsscan import FsScanner, create_scanner from ..fsscan import create_scanner
from ..jwt import validate_bearer from ..jwt import validate_bearer
router = APIRouter() router = APIRouter()
@ -15,10 +15,14 @@ router = APIRouter()
) )
async def trigger_scan( async def trigger_scan(
tasks: BackgroundTasks, tasks: BackgroundTasks,
scanner: Annotated[FsScanner, Depends(create_scanner)],
_: Annotated[None, Security(validate_bearer, scopes=["scanner.trigger"])], _: Annotated[None, Security(validate_bearer, scopes=["scanner.trigger"])],
): ):
""" """
Trigger a full scan of the filesystem, trying to find new videos & deleting old ones. Trigger a full scan of the filesystem, trying to find new videos & deleting old ones.
""" """
tasks.add_task(scanner.scan)
async def run():
async with create_scanner() as scanner:
await scanner.scan()
tasks.add_task(run)