feat(server/m7-scan-progress): wire stagePublisher into 4 scan stages

Each of the 4 stage workers (library walk, MBID backfill, cover
enrich, artist art enrich) gains a progressCb parameter that
receives a snapshot of the current running state per item processed.
The orchestrator stores the snapshot in a local var that the
publisher's marshal closure reads at flush time.

scanrun.go's 4 stage blocks are rewritten to construct one publisher
per stage, pass a Tick-firing closure to the worker as progressCb,
and call Flush() after the worker returns (routing any persist error
to captureErr — preserves today's diagnostic behavior).

The previous post-stage UpdateScanRun* calls are removed; the
publisher's Flush handles the final write. Cadence: every 500 items
OR every 1s, whichever fires first.

Outside-orchestrator callers (scanner_test.go, enricher_test.go)
pass nil for progressCb — no-op behavior preserved for tests that
don't need progress observability.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-06 21:14:50 -04:00
parent 7b9ea131a2
commit 3e9e46f190
7 changed files with 141 additions and 45 deletions
+14 -1
View File
@@ -46,7 +46,8 @@ type BackfillMBIDsResult struct {
// limit caps how many albums are processed in one call. Pass -1 for no
// cap. The caller normally batches (e.g. limit=500 per boot) to avoid
// stalling startup on huge libraries.
func BackfillMBIDs(ctx context.Context, pool *pgxpool.Pool, logger *slog.Logger, limit int) (BackfillMBIDsResult, error) {
func BackfillMBIDs(ctx context.Context, pool *pgxpool.Pool, logger *slog.Logger,
limit int, progressCb func(BackfillMBIDsResult)) (BackfillMBIDsResult, error) {
q := dbq.New(pool)
queryLimit := int32(limit)
if limit < 0 {
@@ -68,6 +69,9 @@ func BackfillMBIDs(ctx context.Context, pool *pgxpool.Pool, logger *slog.Logger,
albumMBID, artistMBID := readMBIDsForFile(r.TrackFilePath, logger)
if albumMBID == "" {
res.Skipped++
if progressCb != nil {
progressCb(res)
}
continue
}
@@ -85,11 +89,17 @@ func BackfillMBIDs(ctx context.Context, pool *pgxpool.Pool, logger *slog.Logger,
logger.Info("mbid backfill: duplicate album mbid (canonical row already owns it)",
"album_id", r.AlbumID, "mbid", albumMBID)
res.Duplicates++
if progressCb != nil {
progressCb(res)
}
continue
}
logger.Warn("mbid backfill: set album mbid failed",
"album_id", r.AlbumID, "err", err)
res.Skipped++
if progressCb != nil {
progressCb(res)
}
continue
}
@@ -124,6 +134,9 @@ func BackfillMBIDs(ctx context.Context, pool *pgxpool.Pool, logger *slog.Logger,
"processed", res.Processed, "healed", res.Healed,
"skipped", res.Skipped, "duplicates", res.Duplicates)
}
if progressCb != nil {
progressCb(res)
}
}
logger.Info("mbid backfill complete",