Skip to content

Commit

Permalink
fix(migration): enhance job progress logging in RunMigration function
Browse files Browse the repository at this point in the history
  • Loading branch information
virajbhartiya committed Nov 29, 2024
1 parent e73f367 commit 2ab8e32
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions migration/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package migration

import (
"context"
"fmt"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -106,13 +107,17 @@ func RunMigration(ctx context.Context, cfg Config, cache MigrationCache, store c
for {
select {
case <-time.After(cfg.ProgressLogPeriod):
jobsNow := jobCount // Snapshot values to avoid incorrect-looking arithmetic if they change.
doneNow := doneCount
pendingNow := jobsNow - doneNow
jobsNow := atomic.LoadUint32(&jobCount)
doneNow := atomic.LoadUint32(&doneCount)
elapsed := time.Since(startTime)
rate := float64(doneNow) / elapsed.Seconds()
log.Log(rt.INFO, "%d jobs created, %d done, %d pending after %v (%.0f/s)",
jobsNow, doneNow, pendingNow, elapsed, rate)

jobsStr := fmt.Sprintf("%d", jobsNow)
doneStr := fmt.Sprintf("%d", doneNow)
rateStr := fmt.Sprintf("%.0f", rate)

log.Log(rt.INFO, "Performing migration: %s of %s jobs processed (%s/s) [%v elapsed]",
doneStr, jobsStr, rateStr, elapsed.Round(time.Second))
case <-workersFinished:
return
case <-ctx.Done():
Expand Down

0 comments on commit 2ab8e32

Please sign in to comment.