Skip to content

Commit

Permalink
Merge pull request #9099 from priyawadhwa/limit-json
Browse files Browse the repository at this point in the history
print download progress every second
  • Loading branch information
priyawadhwa committed Aug 28, 2020
2 parents 214ff5b + 8a2ebd5 commit bdd4fb6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/minikube/download/json_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"io"
"sync"
"time"

"github.com/hashicorp/go-getter"
"k8s.io/minikube/pkg/minikube/out/register"
Expand All @@ -44,6 +45,7 @@ func (cpb *jsonOutput) TrackProgress(src string, currentSize, totalSize int64, s
artifact: src,
current: currentSize,
total: totalSize,
Time: time.Now(),
},
close: func() error {
cpb.lock.Lock()
Expand All @@ -59,12 +61,17 @@ type jsonReader struct {
current int64
total int64
io.Reader
time.Time
}

func (r *jsonReader) Read(p []byte) (n int, err error) {
n, err = r.Reader.Read(p)
r.current += int64(n)
progress := float64(r.current) / float64(r.total)
register.PrintDownloadProgress(r.artifact, fmt.Sprintf("%v", progress))
// print progress every second so user isn't overwhelmed with events
if t := time.Now(); t.Sub(r.Time) > time.Second || progress == 1 {
register.PrintDownloadProgress(r.artifact, fmt.Sprintf("%v", progress))
r.Time = t
}
return
}

0 comments on commit bdd4fb6

Please sign in to comment.