From 7a0628eaf83b8084f4996509e1931229b56dc09f Mon Sep 17 00:00:00 2001 From: Eduardo Cuducos <4732915+cuducos@users.noreply.github.com> Date: Wed, 22 Apr 2026 15:07:48 -0400 Subject: [PATCH] Uses custom logger on `Stop` too --- backfill/backfill.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/backfill/backfill.go b/backfill/backfill.go index 66543201..d7bbd870 100644 --- a/backfill/backfill.go +++ b/backfill/backfill.go @@ -94,6 +94,8 @@ type Backfiller struct { stop chan chan struct{} + log *slog.Logger + Directory identity.Directory } @@ -200,15 +202,15 @@ func NewBackfiller( func (b *Backfiller) StartWithLogger(log *slog.Logger) { ctx := context.Background() - log = log.With("source", "backfiller", "name", b.Name) - log.Info("starting backfill processor") + b.log = log.With("source", "backfiller", "name", b.Name) + b.log.Info("starting backfill processor") sem := semaphore.NewWeighted(int64(b.ParallelBackfills)) for { select { case stopped := <-b.stop: - log.Info("stopping backfill processor") + b.log.Info("stopping backfill processor") sem.Acquire(ctx, int64(b.ParallelBackfills)) close(stopped) return @@ -219,7 +221,7 @@ func (b *Backfiller) StartWithLogger(log *slog.Logger) { dequeueStart := time.Now() job, err := b.Store.GetNextEnqueuedJob(ctx) if err != nil { - log.Error("failed to get next enqueued job", "error", err) + b.log.Error("failed to get next enqueued job", "error", err) time.Sleep(1 * time.Second) continue } else if job == nil { @@ -228,7 +230,7 @@ func (b *Backfiller) StartWithLogger(log *slog.Logger) { } backfillDispatchSeconds.WithLabelValues(b.Name, "dequeue").Observe(time.Since(dequeueStart).Seconds()) - log := log.With("repo", job.Repo()) + log := b.log.With("repo", job.Repo()) // Mark the backfill as "in progress" setStateStart := time.Now() @@ -272,13 +274,16 @@ func (b *Backfiller) Start() { // Stop stops the backfill processor func (b *Backfiller) Stop(ctx context.Context) error { - log := slog.With("source", "backfiller", "name", b.Name) - log.Info("stopping backfill processor") + if b.log != nil { + b.log.Info("stopping backfill processor") + } stopped := make(chan struct{}) b.stop <- stopped select { case <-stopped: - log.Info("backfill processor stopped") + if b.log != nil { + b.log.Info("backfill processor stopped") + } return nil case <-ctx.Done(): return ctx.Err() -- 2.51.2