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
|
aiohttp
|
||||||
watchfiles
|
watchfiles
|
||||||
langcodes
|
langcodes
|
||||||
psycopg[binary]
|
psycopg[binary,pool]
|
||||||
|
|
||||||
|
@ -1,18 +1,35 @@
|
|||||||
import logging
|
import logging
|
||||||
|
from contextlib import asynccontextmanager
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
from psycopg import AsyncConnection
|
||||||
|
from psycopg_pool import AsyncConnectionPool
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logging.getLogger("watchfiles").setLevel(logging.WARNING)
|
logging.getLogger("watchfiles").setLevel(logging.WARNING)
|
||||||
logging.getLogger("rebulk").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(
|
app = FastAPI(
|
||||||
title="Scanner",
|
title="Scanner",
|
||||||
description="API to control the long running scanner or interacting with external databases (themoviedb, tvdb...)\n\n"
|
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.",
|
+ "Most of those APIs are for admins only.",
|
||||||
root_path="/scanner",
|
root_path="/scanner",
|
||||||
# lifetime=smth
|
lifetime=lifetime,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ class Scanner:
|
|||||||
logger.error("Couldn't identify %s.", path, exc_info=e)
|
logger.error("Couldn't identify %s.", path, exc_info=e)
|
||||||
created = await self._client.create_videos(vids)
|
created = await self._client.create_videos(vids)
|
||||||
|
|
||||||
await enqueue(
|
await self._requests.enqueue(
|
||||||
[
|
[
|
||||||
Request(
|
Request(
|
||||||
kind=x.guess.kind,
|
kind=x.guess.kind,
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
from enum import Enum
|
from enum import StrEnum
|
||||||
|
|
||||||
from ..utils import Model
|
from ..utils import Model
|
||||||
|
|
||||||
|
|
||||||
class ExtraKind(str, Enum):
|
class ExtraKind(StrEnum):
|
||||||
OTHER = "other"
|
OTHER = "other"
|
||||||
TRAILER = "trailer"
|
TRAILER = "trailer"
|
||||||
INTERVIEW = "interview"
|
INTERVIEW = "interview"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from enum import Enum
|
from enum import StrEnum
|
||||||
|
|
||||||
|
|
||||||
class Genre(str, Enum):
|
class Genre(StrEnum):
|
||||||
ACTION = "action"
|
ACTION = "action"
|
||||||
ADVENTURE = "adventure"
|
ADVENTURE = "adventure"
|
||||||
ANIMATION = "animation"
|
ANIMATION = "animation"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from enum import Enum
|
from enum import StrEnum
|
||||||
|
|
||||||
from langcodes import Language
|
from langcodes import Language
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ from .staff import Staff
|
|||||||
from .studio import Studio
|
from .studio import Studio
|
||||||
|
|
||||||
|
|
||||||
class MovieStatus(str, Enum):
|
class MovieStatus(StrEnum):
|
||||||
UNKNOWN = "unknown"
|
UNKNOWN = "unknown"
|
||||||
FINISHED = "finished"
|
FINISHED = "finished"
|
||||||
PLANNED = "planned"
|
PLANNED = "planned"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from enum import Enum
|
from enum import StrEnum
|
||||||
|
|
||||||
from langcodes import Language
|
from langcodes import Language
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ from .staff import Staff
|
|||||||
from .studio import Studio
|
from .studio import Studio
|
||||||
|
|
||||||
|
|
||||||
class SerieStatus(str, Enum):
|
class SerieStatus(StrEnum):
|
||||||
UNKNOWN = "unknown"
|
UNKNOWN = "unknown"
|
||||||
FINISHED = "finished"
|
FINISHED = "finished"
|
||||||
AIRING = "airing"
|
AIRING = "airing"
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from enum import Enum
|
from enum import StrEnum
|
||||||
|
|
||||||
from ..utils import Model
|
from ..utils import Model
|
||||||
from .metadataid import MetadataId
|
from .metadataid import MetadataId
|
||||||
|
|
||||||
|
|
||||||
class Role(str, Enum):
|
class Role(StrEnum):
|
||||||
ACTOR = "actor"
|
ACTOR = "actor"
|
||||||
DIRECTOR = "director"
|
DIRECTOR = "director"
|
||||||
WRITTER = "writter"
|
WRITTER = "writter"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user