-
Notifications
You must be signed in to change notification settings - Fork 10
/
task_handler.go
58 lines (48 loc) · 1.63 KB
/
task_handler.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
package taskrunner
import (
"sort"
)
func NewTaskHandler(execution *taskExecution) *TaskHandler {
return &TaskHandler{
execution: execution,
}
}
type TaskHandler struct {
execution *taskExecution
}
func (h *TaskHandler) Definition() *Task {
return h.execution.definition
}
func (h *TaskHandler) Invalidate(reason InvalidationEvent) {
h.execution.Invalidate(reason)
}
type TaskHandlerExecutionState string
const (
TaskHandlerExecutionState_Invalid TaskHandlerExecutionState = "invalid"
TaskHandlerExecutionState_Running = "running"
TaskHandlerExecutionState_Error = "error"
TaskHandlerExecutionState_Done = "done"
TaskHandlerExecutionState_Canceled = "canceled"
)
var TaskHandlerExecutionStateMap = map[taskExecutionState]TaskHandlerExecutionState{
taskExecutionState_invalid: TaskHandlerExecutionState_Invalid,
taskExecutionState_running: TaskHandlerExecutionState_Running,
taskExecutionState_error: TaskHandlerExecutionState_Error,
taskExecutionState_done: TaskHandlerExecutionState_Done,
taskExecutionState_canceled: TaskHandlerExecutionState_Canceled,
}
func (h *TaskHandler) State() TaskHandlerExecutionState {
return TaskHandlerExecutionStateMap[h.execution.state]
}
func (e *Executor) Tasks() []*TaskHandler {
handlers := make([]*TaskHandler, len(e.tasks))
var i int
for _, execution := range e.tasks {
handlers[i] = NewTaskHandler(execution)
i++
}
sort.Slice(handlers, func(a, b int) bool {
return handlers[a].execution.definition.Name < handlers[b].execution.definition.Name
})
return handlers
}