-
Notifications
You must be signed in to change notification settings - Fork 43
/
task.go
55 lines (46 loc) · 1.3 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
package sync
import (
"strings"
)
type taskType string
const (
addItemTask taskType = "ADD_ITEM"
removeItemTask taskType = "REMOVE_ITEM"
createBucketTask taskType = "CREATE_BUCKET"
pinFileTask taskType = "PIN_FILE"
unpinFileTask taskType = "UNPIN_FILE"
bucketBackupOnTask taskType = "TOGGLE_BACKUP_ON"
bucketBackupOffTask taskType = "TOGGLE_BACKUP_OFF"
bucketRestoreTask taskType = "BUCKET_RESTORE"
restoreFileTask taskType = "RESTORE_FILE"
)
type taskState string
const (
taskQueued taskState = "QUEUED"
taskPending taskState = "PENDING"
taskSucceeded taskState = "SUCCESS"
taskFailed taskState = "FAILED"
taskDequeued taskState = "DEQUEUED"
)
type Task struct {
ID string `json:"id"`
State taskState `json:"state"`
Type taskType `json:"type"`
Args []string `json:"args"`
Parallelizable bool `json:"parallelizable"`
// Set to -1 for infinite retries
MaxRetries int `json:"maxRetries"`
Retries int `json:"retries"`
}
func newTask(t taskType, args []string) *Task {
id := string(t) + "_" + strings.Join(args, "_")
return &Task{
ID: id,
State: taskQueued,
Type: t,
Args: args,
Parallelizable: false,
MaxRetries: -1,
Retries: 0,
}
}