mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Proper app cleanup
This commit is contained in:
parent
decb09ecca
commit
ffd4fb2fa6
@ -25,9 +25,9 @@ async def lifespan(_):
|
|||||||
get_db() as db,
|
get_db() as db,
|
||||||
KyooClient() as client,
|
KyooClient() as client,
|
||||||
TheMovieDatabase() as tmdb,
|
TheMovieDatabase() as tmdb,
|
||||||
|
RequestProcessor(db, client, CompositeProvider(tmdb)) as processor
|
||||||
):
|
):
|
||||||
processor = RequestProcessor(db, client, CompositeProvider(tmdb))
|
# creating the processor makes it listen to requests event in pg
|
||||||
await processor.listen_for_requests()
|
|
||||||
async with (
|
async with (
|
||||||
get_db() as db,
|
get_db() as db,
|
||||||
KyooClient() as client,
|
KyooClient() as client,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
from types import TracebackType
|
||||||
from typing import Annotated, Literal
|
from typing import Annotated, Literal
|
||||||
|
|
||||||
from asyncpg import Connection
|
from asyncpg import Connection
|
||||||
@ -61,9 +62,18 @@ class RequestProcessor:
|
|||||||
self._client = client
|
self._client = client
|
||||||
self._providers = providers
|
self._providers = providers
|
||||||
|
|
||||||
async def listen_for_requests(self):
|
async def __aenter__(self):
|
||||||
logger.info("Listening for requestes")
|
logger.info("Listening for requestes")
|
||||||
await self._database.add_listener("scanner.requests", self.process_request)
|
await self._database.add_listener("scanner.requests", self.process_request)
|
||||||
|
return self
|
||||||
|
|
||||||
|
async def __aexit__(
|
||||||
|
self,
|
||||||
|
exc_type: type[BaseException] | None,
|
||||||
|
exc_value: BaseException | None,
|
||||||
|
traceback: TracebackType | None,
|
||||||
|
):
|
||||||
|
await self._database.remove_listener("scanner.requests", self.process_request)
|
||||||
|
|
||||||
async def process_request(self):
|
async def process_request(self):
|
||||||
cur = await self._database.fetchrow(
|
cur = await self._database.fetchrow(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user