1package scheduler 2 3import ( 4 "fmt" 5 "time" 6) 7 8type planStatus int 9 10const ( 11 New planStatus = iota 12 InProgress 13 Finished 14 Error 15 Invalid 16) 17 18func (s planStatus) String() string { 19 switch s { 20 case New: 21 return "New" 22 case InProgress: 23 return "InProgress" 24 case Finished: 25 return "Finished" 26 case Error: 27 return "Error" 28 case Invalid: 29 return "Invalid" 30 default: 31 panic(fmt.Sprintf("invalid status: %d", s)) 32 } 33} 34 35type plan struct { 36 PlanFiles []string 37 ProgressFiles map[string]time.Time 38 Finished []string 39 ErrorFile string 40} 41 42func (ps plan) Status() planStatus { 43 if len(ps.PlanFiles) != 1 || len(ps.Finished) > 1 || (len(ps.Finished) > 0 && ps.ErrorFile != "") { 44 return Invalid 45 } 46 47 if len(ps.Finished) > 0 { 48 return Finished 49 } 50 51 if ps.ErrorFile != "" { 52 return Error 53 } 54 55 if len(ps.ProgressFiles) > 0 { 56 return InProgress 57 } 58 59 return New 60} 61