-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtask.go
More file actions
70 lines (59 loc) · 1.69 KB
/
task.go
File metadata and controls
70 lines (59 loc) · 1.69 KB
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
package gocelery
import (
"bytes"
"fmt"
"time"
)
const celeryTimeFormat = `"2006-01-02T15:04:05.999999"`
type celeryTime struct {
time.Time
}
var null = []byte("null")
func (ct *celeryTime) UnmarshalJSON(data []byte) (err error) {
if bytes.Equal(data, null) {
return
}
t, err := time.Parse(celeryTimeFormat, string(data))
if err == nil {
*ct = celeryTime{t}
}
return
}
func (ct *celeryTime) MarshalJSON() (data []byte, err error) {
if ct.IsZero() {
return null, nil
}
return []byte(ct.UTC().Format(celeryTimeFormat)), nil
}
// Task represents the a single piece of work
type Task struct {
Task string `json:"task"`
ID string `json:"id"`
Args []interface{} `json:"args,omitempty"`
Kwargs map[string]interface{} `json:"kwargs,omitempty"`
Retries int `json:"retries,omitempty"`
Eta celeryTime `json:"eta,omitempty"`
Expires celeryTime `json:"expires,omitempty"`
ContentType string `json:"-"`
}
func (t Task) String() string {
return fmt.Sprintf("ID: %s, Task: %s, Args: %s", t.ID, t.Task, t.Args)
}
// ResultStatus is the valid statuses for task executions
type ResultStatus string
// ResultStatus values
const (
Pending ResultStatus = "PENDING"
Started ResultStatus = "STARTED"
Success ResultStatus = "SUCCESS"
Retry ResultStatus = "RETRY"
Failure ResultStatus = "FAILURE"
Revoked ResultStatus = "REVOKED"
)
// TaskResult is the result wrapper for task
type TaskResult struct {
ID string `json:"task_id"`
Result interface{} `json:"result"`
Status ResultStatus `json:"status"`
TraceBack string `json:"traceback"`
}