-
Notifications
You must be signed in to change notification settings - Fork 128
/
full.go
51 lines (42 loc) · 952 Bytes
/
full.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"math/rand"
"sync"
"time"
"github.com/gosuri/uiprogress"
"github.com/gosuri/uiprogress/util/strutil"
)
var steps = []string{
"downloading source",
"installing deps",
"compiling",
"packaging",
"seeding database",
"deploying",
"staring servers",
}
func main() {
fmt.Println("apps: deployment started: app1, app2")
uiprogress.Start()
var wg sync.WaitGroup
wg.Add(1)
go deploy("app1", &wg)
wg.Add(1)
go deploy("app2", &wg)
wg.Wait()
fmt.Println("apps: successfully deployed: app1, app2")
}
func deploy(app string, wg *sync.WaitGroup) {
defer wg.Done()
bar := uiprogress.AddBar(len(steps)).AppendCompleted().PrependElapsed()
bar.Width = 50
// prepend the deploy step to the bar
bar.PrependFunc(func(b *uiprogress.Bar) string {
return strutil.Resize(app+": "+steps[b.Current()-1], 22)
})
rand.Seed(500)
for bar.Incr() {
time.Sleep(time.Millisecond * time.Duration(rand.Intn(2000)))
}
}