Person Updater overhaul

This commit is contained in:
2026-06-16 18:46:17 +02:00
parent a59cff3951
commit 6ca1a245a3
16 changed files with 984 additions and 920 deletions
+33
View File
@@ -27,6 +27,12 @@ Environment variables
MATCH_PATH default /config/matches.json
WEB_PORT default 8080
WEB_HOST default 0.0.0.0
UPDATER_ENABLED default true (run the person updater on cron)
UPDATER_SCHEDULE cron expression for the person updater,
default "0 10 * * 0" = Sundays 10:00
(local time — set TZ inside the container!)
PERSON_PERF_PATH JSON file for person updater timing.
Default /config/person_perf_stats.json
"""
from __future__ import annotations
@@ -51,6 +57,15 @@ sys.path.insert(0, str(_BASE / "src" / "ln"))
from MatchesCache import MatchesCache # noqa: E402
from LightNovelOrchestrator import LightNovelOrchestrator # noqa: E402
from MatchesWebApp import MatchesWebApp # noqa: E402
from PerfStats import PerfStats # noqa: E402
from CronRunner import CronRunner # noqa: E402
def _env_bool(name: str, default: bool) -> bool:
raw = os.environ.get(name)
if raw is None:
return default
return raw.strip().lower() in ("1", "true", "yes", "y", "on")
def _env_str(name: str, default: "str | None" = None,
@@ -98,6 +113,10 @@ def main() -> int:
web_host = _env_str("WEB_HOST", "0.0.0.0") or "0.0.0.0"
web_port = _env_int("WEB_PORT", 8080)
library_ids = _env_int_list("LIBRARY_IDS")
updater_enabled = _env_bool("UPDATER_ENABLED", True)
updater_schedule = _env_str("UPDATER_SCHEDULE", "0 10 * * 0")
person_perf_path = _env_str("PERSON_PERF_PATH",
"/config/person_perf_stats.json") or None
print(f"[main] kavita url = {kavita_url}", flush=True)
print(f"[main] language = {language}", flush=True)
@@ -107,6 +126,7 @@ def main() -> int:
print(f"[main] web = {web_host}:{web_port}", flush=True)
cache = MatchesCache(match_path)
person_perf = PerfStats(person_perf_path)
orchestrator = LightNovelOrchestrator(
kavita_url=kavita_url,
kavita_api_key=kavita_api_key,
@@ -118,9 +138,22 @@ def main() -> int:
app = MatchesWebApp(
cache, orchestrator=orchestrator,
default_library_ids=library_ids,
person_perf=person_perf,
host=web_host, port=web_port,
)
app.start()
if updater_enabled:
try:
CronRunner(
updater_schedule,
lambda: orchestrator.sync_persons(trigger="cron",
perf=person_perf),
name="person-updater").start()
except ValueError as exc:
print(f"[main] UPDATER_SCHEDULE invalid ({exc}); "
f"scheduled person sync DISABLED", flush=True)
app.wait()
return 0