/
option.go
126 lines (107 loc) · 2.94 KB
/
option.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package task
import (
"time"
"github.com/songzhibin97/gkit/options"
)
// SetGroupID 设置多群组中id
func SetGroupID(id string) options.Option {
return func(t interface{}) {
t.(*Signature).GroupID = id
}
}
// SetPriority 设置任务优先级
func SetPriority(priority uint8) options.Option {
return func(t interface{}) {
t.(*Signature).Priority = priority
}
}
// SetRetryCount 设置重试次数
func SetRetryCount(count int) options.Option {
return func(t interface{}) {
t.(*Signature).RetryCount = count
}
}
// SetRetryInterval 设置间隔时间
func SetRetryInterval(interval int) options.Option {
return func(t interface{}) {
t.(*Signature).RetryInterval = interval
}
}
// SetStopTaskDeletionOnError 设置任务出错后是否删除
func SetStopTaskDeletionOnError(deleteOnErr bool) options.Option {
return func(t interface{}) {
t.(*Signature).StopTaskDeletionOnError = deleteOnErr
}
}
// SetIgnoreNotRegisteredTask 设置任务未注册是否忽略
func SetIgnoreNotRegisteredTask(register bool) options.Option {
return func(t interface{}) {
t.(*Signature).IgnoreNotRegisteredTask = register
}
}
// SetRouter 设置路由
func SetRouter(router string) options.Option {
return func(t interface{}) {
t.(*Signature).Router = router
}
}
// SetArgs 设置参数
func SetArgs(args ...Arg) options.Option {
return func(t interface{}) {
t.(*Signature).Args = args
}
}
// AddArgs 追加参数
func AddArgs(args ...Arg) options.Option {
return func(t interface{}) {
t.(*Signature).Args = append(t.(*Signature).Args, args...)
}
}
// SetMetaSafe 设置是否创建安全的meta
func SetMetaSafe(safe bool) options.Option {
return func(t interface{}) {
t.(*Signature).MetaSafe = safe
}
}
// SetMeta 设置Meta
func SetMeta(meta *Meta) options.Option {
return func(t interface{}) {
t.(*Signature).Meta = meta
}
}
// SetETATime 延时任务设置执行时间
func SetETATime(after *time.Time) options.Option {
return func(t interface{}) {
t.(*Signature).ETA = after
}
}
// SetCallbackOnSuccess 设置成功后回调
func SetCallbackOnSuccess(tasks ...*Signature) options.Option {
return func(t interface{}) {
t.(*Signature).CallbackOnSuccess = tasks
}
}
// AddCallbackOnError 追加失败后回调
func AddCallbackOnError(tasks ...*Signature) options.Option {
return func(t interface{}) {
t.(*Signature).CallbackOnError = append(t.(*Signature).CallbackOnError, tasks...)
}
}
// SetCallbackOnError 设置失败后回调
func SetCallbackOnError(tasks ...*Signature) options.Option {
return func(t interface{}) {
t.(*Signature).CallbackOnError = tasks
}
}
// AddCallbackOnSuccess 追加成功后回调
func AddCallbackOnSuccess(tasks ...*Signature) options.Option {
return func(t interface{}) {
t.(*Signature).CallbackOnSuccess = append(t.(*Signature).CallbackOnSuccess, tasks...)
}
}
// SetTriggerChord .
func SetTriggerChord(task *Signature) options.Option {
return func(t interface{}) {
t.(*Signature).CallbackChord = task
}
}