crontab

package
v0.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrJobBlocked = errors.New("job is blocked")
	BlockedLimit  = 2 * time.Second
)

DefaultParser 默认解析器,支持可选的秒字段 支持的表达式格式: - 标准格式(5字段): "分钟 小时 日 月 星期" - 扩展格式(6字段): "秒 分钟 小时 日 月 星期"

字段说明: 秒 (可选): 0-59 分钟: 0-59 小时: 0-23 日: 1-31 月: 1-12 (或 JAN-DEC) 星期: 0-6 (0或7表示周日,或 SUN-SAT)

特殊字符: *: 匹配任意值

Functions

func DataStats

func DataStats() *jsongen.Map

func IsRealBlocked

func IsRealBlocked() error

IsRealBlocked 场景: 任务设置了立即执行, 00:59.999 刚开始执行, 下次执行时间 01:00 跟着就到了, 再次启动了任务, 但没抢到锁, 忽略该次 Blocked

func IsValidSpec added in v0.6.2

func IsValidSpec(spec string, parser ...cron.Parser) bool

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 StopJob

func StopJob(name string) bool

StopJob 通过名称停止任务

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 GetJob

func GetJob(name string) (*Job, bool)

GetJob 通过名称获取任务对象

func (*Job) IsRunning

func (j *Job) IsRunning() bool

func (*Job) Name

func (j *Job) Name() string

func (*Job) Next

func (j *Job) Next() time.Time

func (*Job) Prev

func (j *Job) Prev() time.Time

func (*Job) Stop

func (j *Job) Stop()

type M added in v0.0.10

type M struct{}

func (*M) Runtime added in v0.0.10

func (m *M) Runtime() error

Runtime 重新加载配置时运行

func (*M) Start added in v0.0.10

func (m *M) Start() error

Start 程序启动时初始化

func (*M) Stop added in v0.0.10

func (m *M) Stop() error

Stop 程序退出时运行

type Runner

type Runner interface {
	Run(ctx context.Context) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL