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" "strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time"
) )
type workerQueue struct { type workerQueue struct {
@ -94,22 +93,13 @@ func (wq *workerQueue) startMessagePrinter() {
go func() { go func() {
defer wq.utilWG.Done() defer wq.utilWG.Done()
var msglen int var msglen int
for { for msg := range wq.msgQueue {
select { // clear previous line (avoids leftover trailing characters from progress)
case msg, open := <-wq.msgQueue: fmt.Printf(strings.Repeat(" ", msglen) + "\r")
// clear previous line (avoids leftover trailing characters from progress) fmt.Println(msg)
fmt.Printf(strings.Repeat(" ", msglen) + "\r") msglen, _ = fmt.Printf(" == Jobs == Queue: %4d Active: %4d Total: %4d\r", len(wq.jobQueue), wq.activeWorkers, wq.njobs)
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)
}
} }
fmt.Println()
}() }()
} }