Skip to content

Commit

Permalink
Stop progressbar pool after starting it
Browse files Browse the repository at this point in the history
  • Loading branch information
vyasgun committed Jan 3, 2024
1 parent a51ff98 commit 5a77725
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions cmd/crc/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,41 @@ func runWatchStatus(writer io.Writer, client *daemonclient.Client, cacheDir stri
ramBar *pb.ProgressBar
)

var err error
barPull = pb.NewPool()
isPullInit := false

err := client.SSEClient.Status(func(loadResult *types.ClusterLoadResult) {
err = barPull.Start()
if err != nil {
return err
}
defer func() {
err = barPull.Stop()
}()
err = client.SSEClient.Status(func(loadResult *types.ClusterLoadResult) {
if !isPullInit {
ramBar, cpuBars = createBars(loadResult.CPUUse, writer)
barPull = pb.NewPool(append([]*pb.ProgressBar{ramBar}, cpuBars...)...)
isPullInit = true
err := barPull.Start()
if err != nil {
if stopErr := barPull.Stop(); stopErr != nil {
return
}
barPull.Add(append([]*pb.ProgressBar{ramBar}, cpuBars...)...)
if startErr := barPull.Start(); startErr != nil {
return
}
isPullInit = true
} else if len(loadResult.CPUUse) > len(cpuBars) {
newCPUCount := len(loadResult.CPUUse) - len(cpuBars)
oldCPUCount := len(cpuBars)
if stopErr := barPull.Stop(); stopErr != nil {
return
}
for i := 0; i < newCPUCount; i++ {
bar := createCPUBar(oldCPUCount+i, writer)
barPull.Add(bar)
cpuBars = append(cpuBars, bar)
}
if startErr := barPull.Start(); startErr != nil {
return
}
}

ramBar.SetTotal(loadResult.RAMSize)
Expand Down

0 comments on commit 5a77725

Please sign in to comment.