mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Create a psycopg pool
This commit is contained in:
parent
8da4e5e840
commit
3e15b28ec1
@ -4,5 +4,5 @@ guessit@git+https://github.com/zoriya/guessit
|
||||
aiohttp
|
||||
watchfiles
|
||||
langcodes
|
||||
psycopg[binary]
|
||||
psycopg[binary,pool]
|
||||
|
||||
|
@ -1,18 +1,35 @@
|
||||
import logging
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from fastapi import FastAPI
|
||||
from psycopg import AsyncConnection
|
||||
from psycopg_pool import AsyncConnectionPool
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logging.getLogger("watchfiles").setLevel(logging.WARNING)
|
||||
logging.getLogger("rebulk").setLevel(logging.WARNING)
|
||||
|
||||
pool = AsyncConnectionPool(open=False, kwargs={"autocommit": True})
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifetime():
|
||||
await pool.open()
|
||||
yield
|
||||
await pool.close()
|
||||
|
||||
|
||||
async def get_db() -> AsyncConnection:
|
||||
async with pool.connection() as ret:
|
||||
yield ret
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
title="Scanner",
|
||||
description="API to control the long running scanner or interacting with external databases (themoviedb, tvdb...)\n\n"
|
||||
+ "Most of those APIs are for admins only.",
|
||||
root_path="/scanner",
|
||||
# lifetime=smth
|
||||
lifetime=lifetime,
|
||||
)
|
||||
|
||||
|
||||
|
@ -94,7 +94,7 @@ class Scanner:
|
||||
logger.error("Couldn't identify %s.", path, exc_info=e)
|
||||
created = await self._client.create_videos(vids)
|
||||
|
||||
await enqueue(
|
||||
await self._requests.enqueue(
|
||||
[
|
||||
Request(
|
||||
kind=x.guess.kind,
|
||||
|
@ -1,9 +1,9 @@
|
||||
from enum import Enum
|
||||
from enum import StrEnum
|
||||
|
||||
from ..utils import Model
|
||||
|
||||
|
||||
class ExtraKind(str, Enum):
|
||||
class ExtraKind(StrEnum):
|
||||
OTHER = "other"
|
||||
TRAILER = "trailer"
|
||||
INTERVIEW = "interview"
|
||||
|
@ -1,7 +1,7 @@
|
||||
from enum import Enum
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
class Genre(str, Enum):
|
||||
class Genre(StrEnum):
|
||||
ACTION = "action"
|
||||
ADVENTURE = "adventure"
|
||||
ANIMATION = "animation"
|
||||
|
@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
from enum import Enum
|
||||
from enum import StrEnum
|
||||
|
||||
from langcodes import Language
|
||||
|
||||
@ -13,7 +13,7 @@ from .staff import Staff
|
||||
from .studio import Studio
|
||||
|
||||
|
||||
class MovieStatus(str, Enum):
|
||||
class MovieStatus(StrEnum):
|
||||
UNKNOWN = "unknown"
|
||||
FINISHED = "finished"
|
||||
PLANNED = "planned"
|
||||
|
@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date
|
||||
from enum import Enum
|
||||
from enum import StrEnum
|
||||
|
||||
from langcodes import Language
|
||||
|
||||
@ -16,7 +16,7 @@ from .staff import Staff
|
||||
from .studio import Studio
|
||||
|
||||
|
||||
class SerieStatus(str, Enum):
|
||||
class SerieStatus(StrEnum):
|
||||
UNKNOWN = "unknown"
|
||||
FINISHED = "finished"
|
||||
AIRING = "airing"
|
||||
|
@ -1,12 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from enum import Enum
|
||||
from enum import StrEnum
|
||||
|
||||
from ..utils import Model
|
||||
from .metadataid import MetadataId
|
||||
|
||||
|
||||
class Role(str, Enum):
|
||||
class Role(StrEnum):
|
||||
ACTOR = "actor"
|
||||
DIRECTOR = "director"
|
||||
WRITTER = "writter"
|
||||
|
Loading…
x
Reference in New Issue
Block a user