-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
60 lines (53 loc) · 1.38 KB
/
status.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
package jobs
// Status is the status of a job.
type Status int8
const (
// StatusInvalid represents invalid status values.
StatusInvalid Status = iota
// StatusNew means a job has just been created.
StatusNew
// StatusWorking means the job is being worked on.
StatusWorking
// StatusWaiting means the job is waiting to retry.
StatusWaiting
// StatusSuccess means the job was successful.
StatusSuccess
// StatusFailed means the job failed.
StatusFailed
)
// String gets the string for the status.
func (s Status) String() string {
return statusStrs[s]
}
// MarshalText marshals the value into bytes.
func (s Status) MarshalText() (text []byte, err error) {
return []byte(s.String()), nil
}
// UnmarshalText unmarshals the bytes into the value.
func (s *Status) UnmarshalText(text []byte) error {
*s = parseStatus(string(text))
return nil
}
// statusStrs are status strings.
var statusStrs = map[Status]string{
StatusInvalid: "invalid",
StatusNew: "new",
StatusWorking: "working",
StatusWaiting: "waiting",
StatusSuccess: "success",
StatusFailed: "failed",
}
var strStatuses = map[string]Status{
"new": StatusNew,
"working": StatusWorking,
"waiting": StatusWaiting,
"success": StatusSuccess,
"failed": StatusFailed,
}
// parseStatus parses a status string.
func parseStatus(s string) Status {
if st, ok := strStatuses[s]; ok {
return st
}
return StatusInvalid
}