1 Star 0 Fork 0

h79/goutils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
option.go 1.98 KB
一键复制 编辑 原始数据 按行查看 历史
huqiuyun 提交于 2024-09-24 00:27 . sched option
package scheduler
import (
"gitee.com/h79/goutils/common/option"
"time"
)
const (
DurationOpt = iota + 1
GroupNumOpt
CapacityOpt
LoggEnableOpt
StopOpt
QuitedOpt
TimeLocationOpt
UniqueOpt //唯一检测添加,存在就不添加了
GenerateOrInitFnOpt //更新或初始化函数,在更新时,有 NotExistNewOpt 时生成函数
NotExistNewOpt //更新时,不存在就生成
MinDurationOpt
)
type GenerateOrInitFunc func(group int, tk Task) (Task, Trigger, bool)
func WithUnique() option.Option {
return option.WithOpt(true, "unique", UniqueOpt)
}
func WithGenerateOrInitFunc(fn GenerateOrInitFunc) option.Option {
return option.WithOpt[GenerateOrInitFunc](fn, "generate func", GenerateOrInitFnOpt)
}
func WithNotExistNew() option.Option {
return option.WithOpt(true, "not exist to new", NotExistNewOpt)
}
func WithTaskMinDuration(t time.Duration) option.Option {
return option.WithOpt(t, "task min duration", MinDurationOpt)
}
func WithTimeLocation(lc *time.Location) option.Option {
return option.WithOpt(lc, "time location", TimeLocationOpt)
}
func WithTaskDuration(t time.Duration) option.Option {
return option.WithOpt(t, "task duration", DurationOpt)
}
func WithGroupNum(num int) option.Option {
return option.WithOpt(num, "group number", GroupNumOpt)
}
func WithCapacity(capacity int) option.Option {
return option.WithOpt(capacity, "logger enable", CapacityOpt)
}
func WithLoggerEnabled() option.Option {
return option.WithOpt(true, "", LoggEnableOpt)
}
func WithStop() option.Option {
return option.WithOpt(true, "", StopOpt)
}
func IsStop(opts ...option.Option) bool {
return option.Select(StopOpt, false, opts...)
}
func WithQuited() option.Option {
return option.WithOpt(true, "", QuitedOpt)
}
func IsQuited(opts ...option.Option) bool {
return option.Select(QuitedOpt, false, opts...)
}
func With(s int) []option.Option {
var opts []option.Option
if s == 1 {
opts = append(opts, WithStop())
} else if s == 2 {
opts = append(opts, WithQuited())
}
return opts
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/h79/goutils.git
git@gitee.com:h79/goutils.git
h79
goutils
goutils
v1.22.8

搜索帮助