Skip to content

Commit 3963521

Browse files
committed
[core] Revamped task.State
1 parent 2eefd56 commit 3963521

1 file changed

Lines changed: 33 additions & 8 deletions

File tree

core/task/state.go

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,42 @@
2424

2525
package task
2626

27-
type State string
27+
type State int
2828
const (
29-
STANDBY = State("STANDBY")
30-
CONFIGURED = State("CONFIGURED")
31-
RUNNING = State("RUNNING")
32-
ERROR = State("ERROR")
33-
DONE = State("DONE")
34-
MIXED = State("MIXED")
29+
UNKNOWN State = iota
30+
STANDBY
31+
CONFIGURED
32+
RUNNING
33+
ERROR
34+
DONE
35+
MIXED
3536
)
37+
38+
var _names = []string{
39+
"UNKNOWN",
40+
"STANDBY",
41+
"CONFIGURED",
42+
"RUNNING",
43+
"ERROR",
44+
"DONE",
45+
"MIXED",
46+
}
47+
3648
func (s State) String() string {
37-
return string(s)
49+
if s > MIXED {
50+
return "UNKNOWN"
51+
}
52+
return _names[s]
53+
}
54+
55+
56+
func StateFromString(s string) State {
57+
for i, v := range _names {
58+
if s == v {
59+
return State(i)
60+
}
61+
}
62+
return UNKNOWN
3863
}
3964

4065
func (s State) X(other State) State {

0 commit comments

Comments
 (0)