fix(worker): reconcile every job + backfill owned releases
Wanted releases pressed while the monitor is off never got reconciled, so they lingered on the wanted list. Extract finish_job() and call it for every finished job (not just when monitor.enabled) so the MonitoredRelease transitions to fulfilled. Add fulfill_owned_releases(), run once at startup, to backfill releases already owned at/above the quality cutoff (self-heals items stuck from before this fix). Both idempotent + tested. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,7 +7,7 @@ from lyra_worker.config import get_config
|
||||
from lyra_worker.db import wait_for_db
|
||||
from lyra_worker.discovery import DiscoveryConfig, run_discovery
|
||||
from lyra_worker.library import clear_staging_root
|
||||
from lyra_worker.monitor import MonitorConfig, reconcile, sweep
|
||||
from lyra_worker.monitor import MonitorConfig, fulfill_owned_releases, reconcile, sweep
|
||||
from lyra_worker.pipeline import run_pipeline
|
||||
from lyra_worker.registry import (
|
||||
build_adapters, build_browser, build_probe, build_resolver,
|
||||
@@ -98,6 +98,17 @@ def _run_discovery(conn, sources, browser, config=None) -> None:
|
||||
print(f"worker: discovery done — {result.artists} artists, {result.albums} albums", flush=True)
|
||||
|
||||
|
||||
def finish_job(conn, job_id, mcfg) -> None:
|
||||
"""Feed a finished job's outcome back into its MonitoredRelease. Runs for EVERY job,
|
||||
monitor enabled or not: a manually-wanted release must still transition to fulfilled so
|
||||
it drops off the Wanted list. A no-op for plain (unlinked) requests."""
|
||||
try:
|
||||
reconcile(conn, job_id, mcfg)
|
||||
except Exception as e: # reconcile must never take down the worker loop
|
||||
print(f"worker: reconcile failed for job {job_id}: {e}", flush=True)
|
||||
conn.rollback()
|
||||
|
||||
|
||||
def maybe_run_discovery(conn, sources, browser, config, dcfg, now, last_discover_tick,
|
||||
tick_seconds: float = DISCOVER_TICK_SECONDS) -> float:
|
||||
"""Run discovery at most once per loop iteration, whether triggered by the schedule
|
||||
@@ -127,6 +138,11 @@ def run_forever() -> None:
|
||||
browser = build_browser()
|
||||
probe = build_probe()
|
||||
similarity_sources = build_similarity_sources(get_config(conn))
|
||||
# Backfill: releases pressed while the monitor was off never got reconciled, so they linger
|
||||
# on the wanted list. Fix any already-owned ones once at startup.
|
||||
fixed = fulfill_owned_releases(conn, MonitorConfig.from_config(get_config(conn)))
|
||||
if fixed:
|
||||
print(f"worker: reconciled {fixed} already-owned release(s) to fulfilled", flush=True)
|
||||
print(f"worker: {len(adapters)} adapter(s) enabled: {[a.name for a in adapters]}", flush=True)
|
||||
print("worker: waiting for jobs", flush=True)
|
||||
last_tick = 0.0
|
||||
@@ -167,12 +183,7 @@ def run_forever() -> None:
|
||||
except Exception as e: # one bad job must not take down the worker loop
|
||||
print(f"worker: pipeline failed for job {job_id}: {e}", flush=True)
|
||||
conn.rollback()
|
||||
if mcfg.enabled:
|
||||
try:
|
||||
reconcile(conn, job_id, mcfg)
|
||||
except Exception as e:
|
||||
print(f"worker: reconcile failed for job {job_id}: {e}", flush=True)
|
||||
conn.rollback()
|
||||
finish_job(conn, job_id, mcfg)
|
||||
print(f"worker: finished job {job_id}", flush=True)
|
||||
except psycopg.OperationalError as e:
|
||||
print(f"worker: db connection lost ({e}); reconnecting...", flush=True)
|
||||
|
||||
Reference in New Issue
Block a user