Skip to content

Commit

Permalink
progress: Overall ETA never less than max ETA
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanBaulch committed Aug 25, 2023
1 parent bb0bb0b commit 77b58b2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions progress/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ func (p *Progress) extractDoneAndActiveTrackers() ([]*Tracker, []*Tracker) {
var trackersActive, trackersDone []*Tracker
var activeTrackersProgress int64
p.trackersActiveMutex.RLock()
var maxETA time.Duration
for _, tracker := range p.trackersActive {
if !tracker.IsDone() {
trackersActive = append(trackersActive, tracker)
activeTrackersProgress += int64(tracker.PercentDone())
if eta := tracker.ETA(); eta > maxETA {
maxETA = eta
}
} else {
trackersDone = append(trackersDone, tracker)
}
Expand All @@ -85,6 +89,7 @@ func (p *Progress) extractDoneAndActiveTrackers() ([]*Tracker, []*Tracker) {
// calculate the overall tracker's progress value
p.overallTracker.value = int64(p.LengthDone()+len(trackersDone)) * 100
p.overallTracker.value += activeTrackersProgress
p.overallTracker.minETA = maxETA
if len(trackersActive) == 0 {
p.overallTracker.MarkAsDone()
}
Expand Down
7 changes: 6 additions & 1 deletion progress/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Tracker struct {
timeStart time.Time
timeStop time.Time
value int64
minETA time.Duration
}

// ETA returns the expected time of "arrival" or completion of this tracker. It
Expand All @@ -56,7 +57,11 @@ func (t *Tracker) ETA() time.Duration {
if pDone == 0 {
return time.Duration(0)
}
return time.Duration((int64(timeTaken) / pDone) * (100 - pDone))
eta := time.Duration((int64(timeTaken) / pDone) * (100 - pDone))
if eta < t.minETA {
eta = t.minETA
}
return eta
}

// Increment updates the current value of the task being tracked.
Expand Down

0 comments on commit 77b58b2

Please sign in to comment.