gen-manifests: don't print progress when nothing changed

Update the progress line only when another line was received, which in
this case means a job has started or finished.
No need to keep reprinting the progress.
This commit is contained in:
Achilleas Koutsou 2022-06-23 16:06:26 +02:00 committed by Christian Kellner
parent 6e4a55cf9e
commit d61b553045

View file

@ -5,7 +5,6 @@ import (
"strings"
"sync"
"sync/atomic"
"time"
)
type workerQueue struct {
@ -94,22 +93,13 @@ func (wq *workerQueue) startMessagePrinter() {
go func() {
defer wq.utilWG.Done()
var msglen int
for {
select {
case msg, open := <-wq.msgQueue:
// clear previous line (avoids leftover trailing characters from progress)
fmt.Printf(strings.Repeat(" ", msglen) + "\r")
if !open {
fmt.Println()
return
}
fmt.Println(msg)
default:
msglen, _ = fmt.Printf(" == Jobs == Queue: %4d Active: %4d Total: %4d\r", len(wq.jobQueue), wq.activeWorkers, wq.njobs)
// sleep a bit when printing progress to avoid constantly pushing out the same progress message
time.Sleep(10 * time.Millisecond)
}
for msg := range wq.msgQueue {
// clear previous line (avoids leftover trailing characters from progress)
fmt.Printf(strings.Repeat(" ", msglen) + "\r")
fmt.Println(msg)
msglen, _ = fmt.Printf(" == Jobs == Queue: %4d Active: %4d Total: %4d\r", len(wq.jobQueue), wq.activeWorkers, wq.njobs)
}
fmt.Println()
}()
}