Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/dev/loadgen/pkg/observer/progress.go
2499 views
1
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package observer
6
7
import (
8
"github.com/cheggaaa/pb/v3"
9
10
"github.com/gitpod-io/gitpod/loadgen/pkg/loadgen"
11
)
12
13
// NewProgressBarObserver produces a new progress bar
14
func NewProgressBarObserver(total int) chan<- *loadgen.SessionEvent {
15
res := make(chan *loadgen.SessionEvent)
16
// bar := pb.Full.New(total)
17
tmpl := `{{ green "spinning up:" }} {{ bar . "[" "█" (cycle . "↖" "↗" "↘" "↙" ) " " "]"}} {{speed . }} {{counters . "%s/%s"}}`
18
// start bar based on our template
19
bar := pb.ProgressBarTemplate(tmpl).New(total)
20
21
go func() {
22
defer bar.Finish()
23
for evt := range res {
24
if evt.Kind != loadgen.SessionWorkspaceStart {
25
continue
26
}
27
bar.Increment()
28
bar.Write()
29
}
30
}()
31
return res
32
}
33
34