调整部分options

This commit is contained in:
Yun
2025-09-24 14:50:30 +08:00
parent 062a39b209
commit 0be8fd0cdc
7 changed files with 96 additions and 58 deletions
+36 -14
View File
@@ -7,20 +7,24 @@ import (
)
type Options struct {
logger logger.Logger
location *time.Location
timeout time.Duration
usePriority bool
priorityVal int64
logger logger.Logger
location *time.Location
timeout time.Duration
usePriority bool
priorityVal int64
batchSize int
maxRetryCount int
}
func defaultOptions() Options {
return Options{
logger: logger.NewLogger(),
location: time.Local,
timeout: time.Hour,
usePriority: false,
priorityVal: 0,
logger: logger.NewLogger(),
location: time.Local,
timeout: time.Hour,
usePriority: false,
priorityVal: 0,
batchSize: 100,
maxRetryCount: 100,
}
}
@@ -35,30 +39,48 @@ func newOptions(opts ...Option) Options {
}
// 设置日志
func SetLogger(log logger.Logger) Option {
func WithLogger(log logger.Logger) Option {
return func(o *Options) {
o.logger = log
}
}
// 设定时区
func SetTimeZone(zone *time.Location) Option {
func WithLocation(zone *time.Location) Option {
return func(o *Options) {
o.location = zone
}
}
// 设置任务最长执行时间
func SetTimeout(d time.Duration) Option {
func WithTimeout(d time.Duration) Option {
return func(o *Options) {
o.timeout = d
}
}
// 设置优先级
func SetPriority(priority int64) Option {
func WithPriority(priority int64) Option {
return func(o *Options) {
o.usePriority = true
o.priorityVal = priority
}
}
func WithBatchSize(size int) Option {
return func(o *Options) {
if size <= 1 {
size = 1
}
o.batchSize = size
}
}
func WithMaxRetryCount(count int) Option {
return func(o *Options) {
if count <= 0 {
count = 1
}
o.maxRetryCount = count
}
}