48e3418c7f
First ingest path beyond manual upload (plan §1C). Source abstraction +
the first concrete backend, so a homelab can index an existing library.
- domain: SourceBackend/IndexableSource ports + SourceInfo/SourceFile shapes
- infrastructure/sources: LocalFolderSource (walks a mounted dir, idempotent
source_id = relative path) + registry built from settings
- application: LibraryImportService — batch sibling of UploadService; dedup on
(source, source_id), copy into storage, minimal track (metadata_status=pending,
enrichment fills the rest in 1D), per-file failures isolated
- workers: scan_local_folder arq task (registered) + enqueue helper (503 if
Redis down)
- api: GET /sources, POST /sources/{source}/scan (admin, enqueues), /health
- config: LOCAL_MEDIA_IMPORT_PATH; README + .env.example documented
- tests: scanner, registry, import service (fakes) + DB-gated sources API path
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
34 lines
1.0 KiB
Python
34 lines
1.0 KiB
Python
"""arq worker settings — the queue runtime. Task functions register here.
|
|
|
|
Run with: ``arq app.workers.arq_worker.WorkerSettings``.
|
|
Tasks (download, enrich, transcode) are appended to ``functions`` in later steps.
|
|
"""
|
|
|
|
from typing import Any, ClassVar
|
|
|
|
from arq.connections import RedisSettings
|
|
|
|
from app.core.config import get_settings
|
|
from app.core.logging import configure_logging, get_logger
|
|
from app.workers.tasks.import_task import scan_local_folder
|
|
|
|
log = get_logger("worker")
|
|
|
|
|
|
async def startup(_ctx: dict[str, Any]) -> None:
|
|
settings = get_settings()
|
|
configure_logging(level=settings.log_level, json=settings.log_json)
|
|
log.info("worker_startup", environment=settings.environment)
|
|
|
|
|
|
async def shutdown(_ctx: dict[str, Any]) -> None:
|
|
log.info("worker_shutdown")
|
|
|
|
|
|
class WorkerSettings:
|
|
functions: ClassVar[list[Any]] = [scan_local_folder]
|
|
on_startup = startup
|
|
on_shutdown = shutdown
|
|
max_jobs = get_settings().max_parallel_downloads
|
|
redis_settings = RedisSettings.from_dsn(str(get_settings().redis_url))
|