mirror of
https://github.com/kopia/kopia.git
synced 2026-10-20 05:14:00 -04:00
cli: Fixed ETA estimation of 'snapshot verify' (#1213)
This commit is contained in:
1 parent
6205b55601
commit
cfdbc40756
3 files changed
+11
-7
No files matched your search
@@ -61,8 +61,8 @@ type verifier struct {
|
||||
func (v *verifier) progressCallback(ctx context.Context, enqueued, active, completed int64) {
|
||||
maybeTimeRemaining := ""
|
||||
|
||||
if est, ok := v.tt.Estimate(float64(completed), float64(enqueued)+float64(completed)); ok {
|
||||
maybeTimeRemaining = fmt.Sprintf(" remaining %v (ETA %v)", est.Remaining, formatTimestamp(est.EstimatedEndTime))
|
||||
if est, ok := v.tt.Estimate(float64(completed), float64(enqueued)); ok {
|
||||
maybeTimeRemaining = fmt.Sprintf(", %.1f%% complete, remaining %v (ETA %v)", est.PercentComplete, est.Remaining, formatTimestamp(est.EstimatedEndTime))
|
||||
}
|
||||
|
||||
log(ctx).Infof("Found %v objects, verifying %v, completed %v objects%v.", enqueued, active, completed, maybeTimeRemaining)
|
||||
|
||||
@@ -59,6 +59,8 @@ func (v *Queue) enqueue(ctx context.Context, front bool, callback CallbackFunc)
|
||||
// Process starts N workers, which will be processing elements in the queue until the queue
|
||||
// is empty and all workers are idle or until any of the workers returns an error.
|
||||
func (v *Queue) Process(ctx context.Context, workers int) error {
|
||||
defer v.reportProgress(ctx)
|
||||
|
||||
eg, ctx := errgroup.WithContext(context.Background())
|
||||
|
||||
for i := 0; i < workers; i++ {
|
||||
@@ -125,19 +127,21 @@ func (v *Queue) completed(ctx context.Context) {
|
||||
v.monitor.Broadcast()
|
||||
}
|
||||
|
||||
func (v *Queue) maybeReportProgress(ctx context.Context) {
|
||||
func (v *Queue) reportProgress(ctx context.Context) {
|
||||
cb := v.ProgressCallback
|
||||
if cb == nil {
|
||||
return
|
||||
if cb != nil {
|
||||
cb(ctx, v.enqueuedWork, v.activeWorkerCount, v.completedWork)
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Queue) maybeReportProgress(ctx context.Context) {
|
||||
if clock.Now().Before(v.nextReportTime) {
|
||||
return
|
||||
}
|
||||
|
||||
v.nextReportTime = clock.Now().Add(1 * time.Second)
|
||||
|
||||
cb(ctx, v.enqueuedWork, v.activeWorkerCount, v.completedWork)
|
||||
v.reportProgress(ctx)
|
||||
}
|
||||
|
||||
// OnNthCompletion invokes the provided callback once the returned callback function has been invoked exactly n times.
|
||||
|
||||
@@ -29,7 +29,7 @@ func (v Estimator) Estimate(completed, total float64) (Timings, bool) {
|
||||
if elapsed > 1*time.Second && total > 0 && completed > 0 {
|
||||
completedRatio := completed / total
|
||||
if completedRatio > 1 {
|
||||
completedRatio = 0
|
||||
completedRatio = 1
|
||||
}
|
||||
|
||||
if completedRatio < 0 {
|
||||
|
||||
Reference in new issue
Block a user