/
task.go
101 lines (81 loc) · 1.5 KB
/
task.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package task
import (
"github.com/GoCollaborate/src/constants"
"time"
)
type taskType int
const (
SHORT taskType = iota
LONG
ROUTINE
PERMANENT
)
type taskPriority int
const (
BASE taskPriority = iota
LOW
MEDIUM
HIGH
URGENT
)
type TaskType interface {
GetType() taskType
GetTimeout() time.Time
}
type TaskPriority interface {
GetPriority() taskPriority
}
func (t *taskType) GetType() taskType {
return *t
}
// if return nil, this taks is identified as an routine task
func (t *taskType) GetTimeout() time.Duration {
switch t.GetType() {
case SHORT:
return constants.DEFAULT_PERIOD_SHORT
case LONG:
return constants.DEFAULT_PERIOD_LONG
case PERMANENT:
return constants.DEFAULT_PERIOD_PERMANENT
default:
return constants.DEFAULT_PERIOD_PERMANENT
}
}
func (t *taskPriority) GetPriority() taskPriority {
return *t
}
func NewCollection() *Collection {
return &Collection{}
}
func (cg *Collection) Append(cs ...interface{}) *Collection {
*cg = append(*cg, cs...)
return cg
}
func (cg *Collection) IsEmpty() bool {
return len(*cg) == 0
}
func (cg *Collection) Length() int {
return len(*cg)
}
func (cg *Collection) Filter(f func(interface{}) bool) *Collection {
var (
clct = Collection{}
)
for _, c := range *cg {
if f(c) {
clct = append(clct, c)
}
}
*cg = clct
return cg
}
type Task struct {
Type taskType
Priority taskPriority
Consumable string
Source Collection
Result Collection
Context *TaskContext
Stage int
}
type Collection []interface{}