crontab

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 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 等于 WithSecondOptional()

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 检查定时任务标识是否有效

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