once添加支持不处理回调的配置
This commit is contained in:
@@ -106,7 +106,7 @@ func InitOnce(ctx context.Context, re redis.UniversalClient, keyPrefix string, c
|
|||||||
return nil, errors.New("redis client is nil")
|
return nil, errors.New("redis client is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if call == nil {
|
if call == nil && !op.allowNilFunc {
|
||||||
op.logger.Errorf(ctx, "worker callback is nil")
|
op.logger.Errorf(ctx, "worker callback is nil")
|
||||||
return nil, errors.New("worker callback is nil")
|
return nil, errors.New("worker callback is nil")
|
||||||
}
|
}
|
||||||
@@ -144,6 +144,11 @@ func InitOnce(ctx context.Context, re redis.UniversalClient, keyPrefix string, c
|
|||||||
maxWorkers: op.maxWorkers,
|
maxWorkers: op.maxWorkers,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 不需要回调
|
||||||
|
if call == nil {
|
||||||
|
return wo, nil
|
||||||
|
}
|
||||||
|
|
||||||
// 初始化优先级
|
// 初始化优先级
|
||||||
if op.priorityType != priorityTypeNone {
|
if op.priorityType != priorityTypeNone {
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ type Options struct {
|
|||||||
maxRunCount int // 单个任务最大运行次数 0代表不限
|
maxRunCount int // 单个任务最大运行次数 0代表不限
|
||||||
maxWorkers int // 最大工作协程数
|
maxWorkers int // 最大工作协程数
|
||||||
cronParser *cron.Parser // cron表达式解析器
|
cronParser *cron.Parser // cron表达式解析器
|
||||||
|
allowNilFunc bool // 允许注册nil函数
|
||||||
}
|
}
|
||||||
|
|
||||||
type priorityType int8
|
type priorityType int8
|
||||||
@@ -43,6 +44,7 @@ func defaultOptions() Options {
|
|||||||
maxRunCount: 0,
|
maxRunCount: 0,
|
||||||
maxWorkers: 100,
|
maxWorkers: 100,
|
||||||
cronParser: &parser,
|
cronParser: &parser,
|
||||||
|
allowNilFunc: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,6 +82,13 @@ func WithLocation(zone *time.Location) Option {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 允许注册nil回调函数
|
||||||
|
func WithAllowNilFunc(allow bool) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.allowNilFunc = allow
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 设置任务最长执行时间
|
// 设置任务最长执行时间
|
||||||
func WithTimeout(d time.Duration) Option {
|
func WithTimeout(d time.Duration) Option {
|
||||||
return func(o *Options) {
|
return func(o *Options) {
|
||||||
|
|||||||
Reference in New Issue
Block a user