Files
stufflog3/models/status.go
T
2022-07-18 19:14:45 +02:00

76 lines
1.1 KiB
Go

package models
type Status int
func (s Status) Valid() bool {
return s >= 0 && s < maxStatus
}
func (s Status) Name() string {
if s < 0 || s >= maxStatus {
return "(invalid status)"
}
return StatusLabels[s]
}
func (s Status) Less(s2 Status) bool {
if s == Active && s2 != Active {
return true
}
if s != Active && s2 == Active {
return false
}
if s == Background && s2 != Background {
return true
}
if s != Background && s2 == Background {
return false
}
if s == Available && s2 != Available {
return true
}
if s != Available && s2 == Available {
return false
}
if s == Blocked && s2 != Blocked {
return true
}
if s != Blocked && s2 == Blocked {
return false
}
return s < s2
}
func (s Status) Ended() bool {
switch s {
case Completed, Failed, Dropped:
return true
default:
return false
}
}
const (
Blocked Status = iota
Available
Background
Active
Completed
Failed
Dropped
maxStatus
)
var StatusLabels = map[Status]string{
Blocked: "Blocked",
Available: "Available",
Background: "Background",
Active: "Active",
Completed: "Completed",
Failed: "Failed",
Dropped: "Dropped",
}