feat(discovery): build_similarity_sources + worker sweep/trigger wiring
Adds registry.build_similarity_sources() (always constructs ListenBrainzSource; reachability is a per-run health() concern, not a startup gate) and wires discovery into the worker's main loop: a scheduled sweep gated on discover.enabled + DISCOVER_TICK_SECONDS, and a one-shot discover.requested trigger mirroring the existing scan.requested pattern. Also hardens run_discovery's health-check pass: a source whose health() raises is now logged and skipped instead of aborting the whole sweep (accepted finding from the Task-3 review). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -48,6 +48,19 @@ class DiscoveryResult:
|
||||
albums: int
|
||||
|
||||
|
||||
def _healthy_sources(sources):
|
||||
"""Return sources whose health() is truthy; a source whose health() raises
|
||||
is logged and skipped, never aborting the sweep."""
|
||||
live = []
|
||||
for s in sources:
|
||||
try:
|
||||
if s.health():
|
||||
live.append(s)
|
||||
except Exception as e: # a bad health check must not abort the sweep
|
||||
print(f"worker: discovery source {getattr(s, 'name', '?')} health check failed: {e}", flush=True)
|
||||
return live
|
||||
|
||||
|
||||
def _seed_artists(conn: psycopg.Connection, cfg: DiscoveryConfig):
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
@@ -134,7 +147,7 @@ def run_discovery(conn: psycopg.Connection, sources: list[SimilaritySource],
|
||||
"""Aggregate similar artists across the library's seed artists; upsert suggestions."""
|
||||
seeds = _seed_artists(conn, cfg)
|
||||
followed = _followed_mbids(conn)
|
||||
live = [s for s in sources if s.health()]
|
||||
live = _healthy_sources(sources)
|
||||
|
||||
agg: dict[str, dict] = {}
|
||||
for seed_mbid, _seed_name in seeds:
|
||||
|
||||
Reference in New Issue
Block a user