wip: Start scan request processor

This commit is contained in:
Zoe Roux 2025-05-07 22:47:32 +02:00
parent aeddf3366c
commit 2d397a0ce1
No known key found for this signature in database
5 changed files with 29 additions and 3 deletions

View File

@ -21,7 +21,7 @@ type ImageTask = {
};
// this will only push a task to the image downloader service and not download it instantly.
// this is both done to prevent to many requests to be sent at once and to make sure POST
// this is both done to prevent too many requests to be sent at once and to make sure POST
// requests are not blocked by image downloading or blurhash calculation
export const enqueueOptImage = async (
tx: Transaction,

View File

@ -4,3 +4,4 @@ guessit@git+https://github.com/zoriya/guessit
aiohttp
watchfiles
langcodes
psycopg[binary]

View File

@ -26,7 +26,7 @@ class Scanner:
except re.error as e:
logger.error(f"Invalid ignore pattern. Ignoring. Error: {e}")
async def scan(self, path: Optional[str], remove_deleted=False):
async def scan(self, path: Optional[str] = None, remove_deleted=False):
if path is None:
logger.info("Starting scan at %s. This may take some time...", path)
if self._ignore_pattern:

View File

@ -1,7 +1,7 @@
from hashlib import sha256
from itertools import zip_longest
from logging import getLogger
from typing import Awaitable, Callable, Literal, Optional, cast
from typing import Awaitable, Callable, Literal, cast
from .guess.guess import guessit
from .models.videos import Guess, Video

View File

@ -2,6 +2,7 @@ from __future__ import annotations
from typing import Literal, Optional
from .client import KyooClient
from .models.videos import Guess
from .utils import Model
@ -20,4 +21,28 @@ class Request(Model):
async def enqueue(requests: list[Request]):
# insert all requests
# on conflict(kind,title,year) add to the `videos` list
# notify
# TODO: how will this conflict be handled if the request is already locked for update (being processed)
pass
class RequestProcessor:
def __init__(self, client: KyooClient):
self._client = client
async def process_scan_requests(self):
# select for update skip_locked limit 1
request: Request = ...
if request.kind == "movie":
movie = await providers.get_movie(request.title, request.year)
movie.videos = request.videos
await self._client.create_movie(movie)
else:
serie = await providers.get_serie(request.title, request.year)
# for vid in request.videos:
# for ep in vid.episodes:
# entry = next(x for x in series.entries if (ep.season is None or x.season == ep.season), None)
await self._client.create_serie(serie)
# delete request