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
+54 -24
View File
@@ -28,15 +28,19 @@ Environment variables
MATCH_PATH default /config/matches.json
WEB_PORT default 8080 (Flask web UI for matches.json)
WEB_HOST default 0.0.0.0
UPDATER_ENABLED default true (volume/cover back-fill cron)
UPDATER_SCHEDULE cron expression for the updater scans,
default "0 19 * * 1,4" = 19:00 every Mon + Thu
UPDATER_ENABLED default true (run volume/cover + person updaters on cron)
UPDATER_SCHEDULE cron expression for the periodic updaters,
default "0 10 * * 0" = Sundays 10:00
(local time — set TZ inside the container!)
UPDATER_LOG default /config/volume_updater.log
COVER_CACHE_PATH directory for the persistent cover cache;
empty (default) = temporary cache, deleted on exit
PERF_PATH JSON file for per-step move timing stats;
empty disables profiling. Default /config/perf_stats.json
PERF_PATH JSON file for per-step move timing stats.
Default /config/perf_stats.json (empty disables it)
VOLUME_PERF_PATH JSON file for volume/cover updater timing.
Default /config/volume_perf_stats.json
PERSON_PERF_PATH JSON file for person updater timing.
Default /config/person_perf_stats.json
"""
from __future__ import annotations
@@ -62,7 +66,10 @@ from SuwayomiFolderWatcher import SuwayomiFolderWatcher # noqa: E402,F401
from MatchesCache import MatchesCache # noqa: E402
from MatchesWebApp import MatchesWebApp # noqa: E402
from KavitaVolumeCoverUpdater import KavitaVolumeCoverUpdater # noqa: E402
from KavitaClient import KavitaClient # noqa: E402
from KavitaPersonUpdater import KavitaPersonUpdater # noqa: E402
from PerfStats import PerfStats # noqa: E402
from CronRunner import CronRunner # noqa: E402
def _env_str(name: str, default: "str | None" = None,
@@ -106,10 +113,14 @@ 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)
updater_enabled = _env_bool("UPDATER_ENABLED", True)
updater_schedule = _env_str("UPDATER_SCHEDULE", "0 10 * * 1,4")
updater_schedule = _env_str("UPDATER_SCHEDULE", "0 10 * * 0")
updater_log = _env_str("UPDATER_LOG", "/config/volume_updater.log")
cover_cache_path = _env_str("COVER_CACHE_PATH", "") or None
perf_path = _env_str("PERF_PATH", "/config/perf_stats.json") or None
volume_perf_path = _env_str("VOLUME_PERF_PATH",
"/config/volume_perf_stats.json") or None
person_perf_path = _env_str("PERSON_PERF_PATH",
"/config/person_perf_stats.json") or None
print(f"[main] suwayomi = {suwayomi_path}", flush=True)
print(f"[main] kavita = {kavita_path}", flush=True)
@@ -121,43 +132,62 @@ def main() -> int:
print(f"[main] web = {web_host}:{web_port}", flush=True)
matches_cache = MatchesCache(match_path)
perf_stats = PerfStats(perf_path)
perf_move = PerfStats(perf_path)
perf_volume = PerfStats(volume_perf_path)
perf_person = PerfStats(person_perf_path)
mover = SuwayomiMover(
suwayomi_path, kavita_path,
kavita_base_url=kavita_url,
kavita_api_key=kavita_api_key,
language=language,
request_timeout=request_timeout,
delete_source=delete_source,
matches_cache=matches_cache,
cover_cache_dir=cover_cache_path,
perf_stats=perf_stats,
perf_stats=perf_move,
)
# Standalone, global, id-based person updater (manga + LN libraries).
person_updater = None
if kavita_api_key:
kavita_client = KavitaClient(kavita_url, kavita_api_key,
request_timeout=request_timeout)
person_updater = KavitaPersonUpdater(kavita_client)
# watcher = SuwayomiFolderWatcher(suwayomi_path, mover, settle_seconds=settle_seconds)
web_app = MatchesWebApp(matches_cache, mover=mover, perf_stats=perf_stats,
host=web_host, port=web_port)
web_app = MatchesWebApp(
matches_cache, mover=mover,
person_updater=person_updater, person_trigger="web",
perf_stats={"move": perf_move, "volume": perf_volume,
"person": perf_person},
host=web_host, port=web_port)
web_app.start()
if updater_enabled:
updater = KavitaVolumeCoverUpdater(
kavita_path,
matches_cache=matches_cache,
language=language,
request_timeout=request_timeout,
log_path=updater_log,
cover_cache_dir=cover_cache_path,
perf_stats=perf_volume,
)
def _scheduled_job():
updater.update_all()
if person_updater is not None:
person_updater.update_all_persons(trigger="cron",
perf=perf_person)
try:
updater = KavitaVolumeCoverUpdater(
kavita_path,
matches_cache=matches_cache,
language=language,
request_timeout=request_timeout,
log_path=updater_log,
schedule=updater_schedule,
cover_cache_dir=cover_cache_path,
)
updater.start()
CronRunner(updater_schedule, _scheduled_job,
name="updaters").start()
except ValueError as exc:
# Invalid cron expression — keep the service up, just without
# the updater, and make the config error obvious in the logs.
# the scheduled updaters, and surface the config error.
print(f"[main] UPDATER_SCHEDULE invalid ({exc}); "
f"volume/cover updater DISABLED", flush=True)
f"scheduled updaters DISABLED", flush=True)
# watcher.start()
# watcher.wait() # blocks until stop() is called via a signal