-
Notifications
You must be signed in to change notification settings - Fork 8
/
state.go
53 lines (40 loc) · 1023 Bytes
/
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
package workflow
import (
"strconv"
"github.com/luno/workflow/internal/metrics"
)
//go:generate stringer -type=State
type State int
const (
StateUnknown State = 0
StateShutdown State = 1
StateRunning State = 2
StateIdle State = 3
)
var stateStrings = map[State]string{
StateUnknown: "Unknown",
StateShutdown: "Shutdown",
StateRunning: "Running",
StateIdle: "Idle",
}
func (s State) String() string {
if val, ok := stateStrings[s]; ok {
return val
}
return "State(" + strconv.FormatInt(int64(s), 10) + ")"
}
func (w *Workflow[Type, Status]) updateState(processName string, s State) {
w.internalStateMu.Lock()
defer w.internalStateMu.Unlock()
metrics.ProcessStates.WithLabelValues(w.Name, processName).Set(float64(s))
w.internalState[processName] = s
}
func (w *Workflow[Type, Status]) States() map[string]State {
w.internalStateMu.Lock()
defer w.internalStateMu.Unlock()
states := make(map[string]State)
for k, v := range w.internalState {
states[k] = v
}
return states
}