forked from RichardKnop/machinery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
signature.go
68 lines (58 loc) · 1.54 KB
/
signature.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
package tasks
import (
"fmt"
"time"
"github.com/satori/go.uuid"
)
// Arg represents a single argument passed to invocation fo a task
type Arg struct {
Type string `bson:"type"`
Value interface{} `bson:"value"`
}
// Headers represents the headers which should be used to direct the task
type Headers map[string]interface{}
// Set on Headers implements opentracing.TextMapWriter for trace propagation
func (h Headers) Set(key, val string) {
h[key] = val
}
// ForEachKey on Headers implements opentracing.TextMapReader for trace propagation.
// It is essentially the same as the opentracing.TextMapReader implementation except
// for the added casting from interface{} to string.
func (h Headers) ForeachKey(handler func(key, val string) error) error {
for k, v := range h {
// Skip any non string values
stringValue, ok := v.(string)
if !ok {
continue
}
if err := handler(k, stringValue); err != nil {
return err
}
}
return nil
}
// Signature represents a single task invocation
type Signature struct {
UUID string
Name string
RoutingKey string
ETA *time.Time
GroupUUID string
GroupTaskCount int
Args []Arg
Headers Headers
Immutable bool
RetryCount int
RetryTimeout int
OnSuccess []*Signature
OnError []*Signature
ChordCallback *Signature
}
// NewSignature creates a new task signature
func NewSignature(name string, args []Arg) *Signature {
return &Signature{
UUID: fmt.Sprintf("task_%v", uuid.NewV4()),
Name: name,
Args: args,
}
}