-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtask.go
42 lines (36 loc) · 938 Bytes
/
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
package mq
import (
"encoding/json"
"time"
)
type Task struct {
CreatedAt time.Time `json:"created_at"`
ProcessedAt time.Time `json:"processed_at"`
Expiry time.Time `json:"expiry"`
Error error `json:"error"`
ID string `json:"id"`
Topic string `json:"topic"`
Status string `json:"status"`
Payload json.RawMessage `json:"payload"`
dag any
}
func (t *Task) GetFlow() any {
return t.dag
}
func NewTask(id string, payload json.RawMessage, nodeKey string, opts ...TaskOption) *Task {
if id == "" {
id = NewID()
}
task := &Task{ID: id, Payload: payload, Topic: nodeKey, CreatedAt: time.Now()}
for _, opt := range opts {
opt(task)
}
return task
}
// TaskOption defines a function type for setting options.
type TaskOption func(*Task)
func WithDAG(dag any) TaskOption {
return func(opts *Task) {
opts.dag = dag
}
}