-
Notifications
You must be signed in to change notification settings - Fork 7
/
task.go
72 lines (62 loc) · 1.57 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
package util
import "time"
// Status is the status of the task
type Status string
// list of task status
const (
StatusRetry Status = "retry"
StatusInitiated Status = "initiated"
StatusQueued Status = "queued"
StatusInProgress Status = "in_progress"
StatusFailed Status = "failed"
StatusSuccess Status = "success"
)
// TaskPriority is the priority of the task
type TaskPriority string
// list of TaskPriority
var (
TaskPriorityHigh TaskPriority = "High"
TaskPriorityLow TaskPriority = "Low"
)
// Valid check the task priority
func (p TaskPriority) Valid() bool {
return p == TaskPriorityHigh || p == TaskPriorityLow
}
// Task field hold the necessary field
type Task struct {
TaskID string
PrimaryKey string
Name string
OriginalTaskID string
Retry int
Payload []byte
Priority TaskPriority
Status Status
FailError string
Duration *float64
CreatedAt time.Time
UpdatedAt time.Time
}
// CheckStatusOrder check if status st can be updated by status p
func (p Status) CheckStatusOrder(st Status) bool {
val := map[Status]int{
StatusInitiated: 1,
StatusQueued: 2,
StatusInProgress: 3,
StatusRetry: 4,
StatusFailed: 5,
StatusSuccess: 5,
}
return val[p] > val[st]
}
// TaskDateRangeCount holds necessary values for task and it's statuses in a date range
type TaskDateRangeCount struct {
ID time.Time
Total int
CountRetry int
CountInitiated int
CountQueued int
CountInProgress int
CountSuccess int
CountFailed int
}