Skip to content

Commit b132d4f

Browse files
authored
Merge branch 'main' into 0-do-not-write-state-on-init
2 parents a76d3b9 + c307351 commit b132d4f

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

fracmanager/loader.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ func (l *Loader) discover(ctx context.Context) ([]*frac.Active, []*frac.Sealed,
122122
return nil, nil, nil, err
123123
}
124124

125-
start := time.Now()
126125
total := len(manifests)
126+
logProgress := progressLogger(time.Millisecond * 500)
127127

128128
// Load fractions according to their stage (active, sealed, and remote)
129129
actives := make([]*frac.Active, 0)
@@ -142,7 +142,7 @@ func (l *Loader) discover(ctx context.Context) ([]*frac.Active, []*frac.Sealed,
142142
default:
143143
logger.Error("unexpected fraction stage", zap.Any("manifest", manifest))
144144
}
145-
logDiscoveringProgress(start, i, total)
145+
logProgress(i, total)
146146
}
147147

148148
logger.Info("fractions initialization completed",
@@ -195,16 +195,19 @@ func (l *Loader) scanFiles() []string {
195195
return files
196196
}
197197

198-
// logDiscoveringProgress logs loading progress at regular intervals
198+
// progressLogger returns function that logs discovering progress no more frequently than the specified interval
199199
// Provides visibility into the fraction loading process
200-
func logDiscoveringProgress(startTime time.Time, currentIndex, totalCount int) {
201-
if time.Since(startTime) >= time.Second || currentIndex == totalCount-1 {
202-
progressPercent := 100 * (currentIndex + 1) / totalCount
203-
logger.Info(
204-
"fraction list discovering progress",
205-
zap.String("progress", fmt.Sprintf("%d%%", progressPercent)),
206-
zap.Int("total", totalCount),
207-
zap.Int("loaded", currentIndex+1),
208-
)
200+
func progressLogger(interval time.Duration) func(currentIndex, totalCount int) {
201+
ts := time.Now()
202+
return func(currentIndex, totalCount int) {
203+
if time.Since(ts) >= interval || currentIndex == totalCount-1 || currentIndex == 0 {
204+
logger.Info(
205+
"fraction list discovering",
206+
zap.String("progress", fmt.Sprintf("%d%%", 100*(currentIndex+1)/totalCount)),
207+
zap.Int("total", totalCount),
208+
zap.Int("loaded", currentIndex+1),
209+
)
210+
ts = time.Now()
211+
}
209212
}
210213
}

0 commit comments

Comments
 (0)