scheduler

package
v1.1.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddContextFunc

func AddContextFunc(name string, spec string, runImmediately bool, fn Func) error

AddContextFunc 按 cron 表达式注册一个任务,支持传递带 context 的 func。

func AddFunc

func AddFunc(name string, spec string, fn func()) error

AddFunc 按 cron 表达式注册一个任务,fn 会在独立 goroutine 中执行。 支持 5 字段、6 字段 cron 表达式,以及 @every 1m 这类固定间隔表达式。

func Every

func Every(duration time.Duration) string

func Parse

func Parse(spec string) (schedule, error)

Parse 解析 cron 表达式。 支持:

  • 5 字段:minute hour day-of-month month day-of-week
  • 6 字段:second minute hour day-of-month month day-of-week
  • @every 1m / @every 30s

字段支持 *、*/n、a-b、a-b/n、逗号列表和具体数字。

func Remove

func Remove(name string)

func RemovePrefix

func RemovePrefix(prefix string)

func StopAll

func StopAll()

Types

type Func

type Func func(ctx context.Context)

Func 是 cron 调度器执行的任务函数。 调度器会为每次执行传入可取消的 context,便于任务在重载或关闭时尽快退出。

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

func NewManager

func NewManager() *Manager

func (*Manager) AddContextFunc

func (m *Manager) AddContextFunc(name string, spec string, runImmediately bool, fn Func) error

func (*Manager) AddFunc

func (m *Manager) AddFunc(name string, spec string, fn func()) error

func (*Manager) Remove

func (m *Manager) Remove(name string)

func (*Manager) RemovePrefix

func (m *Manager) RemovePrefix(prefix string)

func (*Manager) StopAll

func (m *Manager) StopAll()

Jump to

Keyboard shortcuts

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