-
Notifications
You must be signed in to change notification settings - Fork 289
/
state.go
91 lines (73 loc) · 1.71 KB
/
state.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package dockercompose
import (
"time"
"github.com/windmilleng/tilt/internal/model"
"github.com/windmilleng/tilt/internal/container"
)
type Status string
// Three hacky states just for now to get something into the hud.
const (
StatusDown = Status("Down")
StatusInProg = Status("In Progress")
StatusUp = Status("OK")
StatusCrash = Status("Crash")
)
var containerActionToStatus = map[Action]Status{
ActionCreate: StatusInProg,
ActionDie: StatusDown,
ActionKill: StatusDown,
ActionRename: StatusInProg,
ActionRestart: StatusUp, // ??
ActionStart: StatusUp,
ActionStop: StatusDown,
ActionUpdate: StatusUp, // ??
}
func (evt Event) GuessStatus() Status {
if evt.Type != TypeContainer {
return ""
}
return containerActionToStatus[evt.Action]
}
func (evt Event) IsStartupEvent() bool {
if evt.Type != TypeContainer {
return false
}
return evt.Action == ActionStart || evt.Action == ActionRestart || evt.Action == ActionUpdate
}
func (evt Event) IsStopEvent() bool {
if evt.Type != TypeContainer {
return false
}
return evt.Action == ActionKill
}
type State struct {
Status Status
ContainerID container.ID
CurrentLog model.Log
StartTime time.Time
IsStopping bool
}
func (State) ResourceState() {}
func (s State) Log() model.Log {
return s.CurrentLog
}
func (s State) WithCurrentLog(l model.Log) State {
s.CurrentLog = l
return s
}
func (s State) WithStatus(status Status) State {
s.Status = status
return s
}
func (s State) WithContainerID(cID container.ID) State {
s.ContainerID = cID
return s
}
func (s State) WithStartTime(time time.Time) State {
s.StartTime = time
return s
}
func (s State) WithStopping(stopping bool) State {
s.IsStopping = stopping
return s
}