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:
@@ -52,7 +52,10 @@ func New(pool *pgxpool.Pool, logger *slog.Logger, paths []string) *Scanner {
|
||||
// Scan walks every configured root and upserts any audio file whose mtime is
|
||||
// newer than the existing row's updated_at. Walk errors and per-file errors
|
||||
// are logged + counted; the scan keeps going.
|
||||
func (s *Scanner) Scan(ctx context.Context) (Stats, error) {
|
||||
//
|
||||
// progressCb (may be nil) receives the current Stats snapshot after each
|
||||
// processed file. Used by the orchestrator to drive partial-tally writes.
|
||||
func (s *Scanner) Scan(ctx context.Context, progressCb func(Stats)) (Stats, error) {
|
||||
var stats Stats
|
||||
q := dbq.New(s.pool)
|
||||
start := time.Now()
|
||||
@@ -65,6 +68,9 @@ func (s *Scanner) Scan(ctx context.Context) (Stats, error) {
|
||||
if err != nil {
|
||||
s.logger.Warn("library scan walk error", "path", path, "err", err)
|
||||
stats.Errored++
|
||||
if progressCb != nil {
|
||||
progressCb(stats)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if d.IsDir() {
|
||||
@@ -77,6 +83,9 @@ func (s *Scanner) Scan(ctx context.Context) (Stats, error) {
|
||||
s.logger.Warn("library scan file error", "path", path, "err", err)
|
||||
stats.Errored++
|
||||
}
|
||||
if progressCb != nil {
|
||||
progressCb(stats)
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return stats, fmt.Errorf("library: walk %q: %w", root, err)
|
||||
|
||||
Reference in New Issue
Block a user