Documentation
¶
Index ¶
- Variables
- func DataStats() *jsongen.Map
- func InitTester()
- func IsRealBlocked() error
- func IsValidSpec(spec string, parser ...cron.Parser) bool
- func SetSkipIfStillRunning(v bool)
- func StopJob(name string) bool
- func StopTester()
- type Job
- func AddJob(ctx context.Context, name, spec string, runner Runner, ...) (*Job, error)
- func AddJobWithFields(ctx context.Context, name, spec string, runner Runner, fields map[string]any, ...) (*Job, error)
- func AddOnceJob(ctx context.Context, name, spec string, runner Runner, ...) (*Job, error)
- func AddOnceJobWithFields(ctx context.Context, name, spec string, runner Runner, fields map[string]any, ...) (*Job, error)
- func GetJob(name string) (*Job, bool)
- type M
- type Runner
Constants ¶
This section is empty.
Variables ¶
var ( ErrJobBlocked = errors.New("job is blocked") BlockedLimit = 2 * time.Second )
var DefaultParser = cron.NewParser( cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor, )
DefaultParser 默认解析器,支持可选的秒字段 支持的表达式格式: - 标准格式(5字段): "分钟 小时 日 月 星期" - 扩展格式(6字段): "秒 分钟 小时 日 月 星期"
字段说明: 秒 (可选): 0-59 分钟: 0-59 小时: 0-23 日: 1-31 月: 1-12 (或 JAN-DEC) 星期: 0-6 (0或7表示周日,或 SUN-SAT)
特殊字符: *: 匹配任意值
Functions ¶
func InitTester ¶ added in v0.10.7
func InitTester()
func IsRealBlocked ¶
func IsRealBlocked() error
IsRealBlocked 场景: 任务设置了立即执行, 00:59.999 刚开始执行, 下次执行时间 01:00 跟着就到了, 再次启动了任务, 但没抢到锁, 忽略该次 Blocked
func IsValidSpec ¶ added in v0.6.2
IsValidSpec 检查定时任务表达式是否有效
示例: "* * * * *" // 每分钟执行 "* * * * * *" // 每秒执行 "0 */5 * * * *" // 每5分钟执行 "0 0 3 * * *" // 每天凌晨3点执行 "0 0 3 1 * *" // 每月1号凌晨3点执行 "0 0 3 * * 1" // 每周一凌晨3点执行
参数:
spec: 定时任务表达式 parser: 可选的解析器,如果不提供则使用默认解析器
返回值:
bool: 表达式是否有效
?: 用于日和星期字段,表示不指定值 -: 范围,如 1-5 /: 步长,如 */5 表示每5个单位 ,: 列表,如 1,3,5 表示1、3、5
func SetSkipIfStillRunning ¶ added in v0.6.8
func SetSkipIfStillRunning(v bool)
SetSkipIfStillRunning 全局设置任务是否单例执行
func StopTester ¶ added in v0.10.7
func StopTester()
Types ¶
type Job ¶
type Job struct {
// contains filtered or unexported fields
}
func AddJob ¶
func AddJob(ctx context.Context, name, spec string, runner Runner, opts ...cron.EntryOption) (*Job, error)
AddJob 添加任务
func AddJobWithFields ¶ added in v0.10.8
func AddJobWithFields(ctx context.Context, name, spec string, runner Runner, fields map[string]any, opts ...cron.EntryOption) (*Job, error)
AddJobWithFields 添加带自定义日志字段的任务 fields: 任务执行时附加到日志中的自定义字段, 这些字段会在错误日志中特别有用
func AddOnceJob ¶ added in v0.10.7
func AddOnceJob(ctx context.Context, name, spec string, runner Runner, opts ...cron.EntryOption) (*Job, error)
AddOnceJob 添加单次任务, 只会执行一次,执行后自动移除