-
Notifications
You must be signed in to change notification settings - Fork 22
/
progress.go
69 lines (57 loc) · 1.71 KB
/
progress.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package controlstatus
import (
"context"
"sync"
)
type ControlProgress struct {
updateLock *sync.Mutex
Total int `json:"total"`
Pending int `json:"pending"`
Complete int `json:"complete"`
Error int `json:"error"`
Executing int `json:"executing"`
StatusSummaries *StatusSummary `json:"summary"`
}
func NewControlProgress(total int) *ControlProgress {
return &ControlProgress{
updateLock: &sync.Mutex{},
Total: total,
Pending: total,
StatusSummaries: &StatusSummary{},
}
}
func (p *ControlProgress) Start(ctx context.Context) {
p.updateLock.Lock()
defer p.updateLock.Unlock()
OnStart(ctx, p)
}
func (p *ControlProgress) OnControlStart(ctx context.Context, controlRun ControlRunStatusProvider) {
p.updateLock.Lock()
defer p.updateLock.Unlock()
// increment the parallel execution count
p.Executing++
// decrement pending count
p.Pending--
OnControlStart(ctx, controlRun, p)
}
func (p *ControlProgress) OnControlComplete(ctx context.Context, controlRun ControlRunStatusProvider) {
p.updateLock.Lock()
defer p.updateLock.Unlock()
p.Complete++
// decrement the parallel execution count
p.Executing--
p.StatusSummaries.Merge(controlRun.GetStatusSummary())
OnControlComplete(ctx, controlRun, p)
}
func (p *ControlProgress) OnControlError(ctx context.Context, controlRun ControlRunStatusProvider) {
p.updateLock.Lock()
defer p.updateLock.Unlock()
p.Error++
// decrement the parallel execution count
p.Executing--
p.StatusSummaries.Merge(controlRun.GetStatusSummary())
OnControlError(ctx, controlRun, p)
}
func (p *ControlProgress) Finish(ctx context.Context) {
OnComplete(ctx, p)
}