-
Notifications
You must be signed in to change notification settings - Fork 7
/
progress.go
66 lines (55 loc) · 1.23 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
package progrock
import (
"time"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)
//go:generate protoc -I=./ --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative progress.proto
// VertexInstance identifies a vertex at a specific point in time.
type VertexInstance struct {
VertexId string
GroupId string
}
func (v *Vertex) Label(name string) string {
for _, label := range v.Labels {
if label.Name == name {
return label.Value
}
}
return ""
}
func (v *Vertex) HasInput(o *Vertex) bool {
for _, oid := range o.Outputs {
if oid == v.Id {
return true
}
for _, iid := range v.Inputs {
if iid == oid {
return true
}
}
}
for _, id := range v.Inputs {
if id == o.Id {
return true
}
}
return false
}
func (vertex *Vertex) Duration() time.Duration {
return Duration(vertex.Started, vertex.Completed)
}
func (task *VertexTask) Duration() time.Duration {
return Duration(task.Started, task.Completed)
}
func Duration(started, completed *timestamppb.Timestamp) time.Duration {
if started == nil {
return 0
}
var end time.Time
if completed != nil {
end = completed.AsTime()
} else {
end = Clock.Now()
}
return end.Sub(started.AsTime())
}