Documentation ¶
Overview ¶
包gcron实现了cron模式解析器和任务执行器。
Index ¶
- Constants
- func DelayAdd(ctx context.Context, delay time.Duration, pattern string, job JobFunc, ...)
- func DelayAddOnce(ctx context.Context, delay time.Duration, pattern string, job JobFunc, ...)
- func DelayAddSingleton(ctx context.Context, delay time.Duration, pattern string, job JobFunc, ...)
- func DelayAddTimes(ctx context.Context, delay time.Duration, pattern string, times int, ...)
- func GetLogger() 日志类.ILogger
- func Remove(name string)
- func SetLogger(logger 日志类.ILogger)
- func Size() int
- func Start(name ...string)
- func Stop(name ...string)
- type Cron
- func (c *Cron) Add(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
- func (c *Cron) AddEntry(ctx context.Context, pattern string, job JobFunc, times int, isSingleton bool, ...) (*Entry, error)
- func (c *Cron) AddOnce(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
- func (c *Cron) AddSingleton(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
- func (c *Cron) AddTimes(ctx context.Context, pattern string, times int, job JobFunc, name ...string) (*Entry, error)
- func (c *Cron) Close()
- func (c *Cron) DelayAdd(ctx context.Context, delay time.Duration, pattern string, job JobFunc, ...)
- func (c *Cron) DelayAddEntry(ctx context.Context, delay time.Duration, pattern string, job JobFunc, ...)
- func (c *Cron) DelayAddOnce(ctx context.Context, delay time.Duration, pattern string, job JobFunc, ...)
- func (c *Cron) DelayAddSingleton(ctx context.Context, delay time.Duration, pattern string, job JobFunc, ...)
- func (c *Cron) DelayAddTimes(ctx context.Context, delay time.Duration, pattern string, times int, ...)
- func (c *Cron) Entries() []*Entry
- func (c *Cron) GetLogger() 日志类.ILogger
- func (c *Cron) Remove(name string)
- func (c *Cron) Search(name string) *Entry
- func (c *Cron) SetLogger(logger 日志类.ILogger)
- func (c *Cron) Size() int
- func (c *Cron) Start(name ...string)
- func (c *Cron) Stop(name ...string)
- type Entry
- func Add(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
- func AddOnce(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
- func AddSingleton(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
- func AddTimes(ctx context.Context, pattern string, times int, job JobFunc, name ...string) (*Entry, error)
- func Entries() []*Entry
- func Search(name string) *Entry
- type JobFunc
Constants ¶
const ( StatusReady = 定时类.StatusReady StatusRunning = 定时类.StatusRunning StatusStopped = 定时类.StatusStopped StatusClosed = 定时类.StatusClosed )
Variables ¶
This section is empty.
Functions ¶
func DelayAdd ¶
func DelayAdd(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)
DelayAdd 在 `delay` 时间后向默认的 cron 对象添加一个定时任务。
func DelayAddOnce ¶
func DelayAddOnce(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)
DelayAddOnce在`delay`时间后向默认的cron对象添加一个定时任务。 这个定时任务只能运行一次。
func DelayAddSingleton ¶
func DelayAddSingleton(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)
DelayAddSingleton 在`delay`时间后向默认的cron对象添加一个单例定时任务。
Types ¶
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
func (*Cron) Add ¶
func (c *Cron) Add(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
Add 添加一个定时任务。 可以用唯一的 `name` 与定时任务进行绑定。 如果 `name` 已经被使用,则返回错误。
func (*Cron) AddEntry ¶
func (c *Cron) AddEntry(ctx context.Context, pattern string, job JobFunc, times int, isSingleton bool, name ...string) (*Entry, error)
AddEntry 创建并返回一个新的 Entry 对象。
func (*Cron) AddOnce ¶
func (c *Cron) AddOnce(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
AddOnce 添加一个仅能运行一次的定时任务。 可以为定时任务绑定一个唯一的 `name`。 如果 `name` 已被使用,则返回错误。
func (*Cron) AddSingleton ¶
func (c *Cron) AddSingleton(ctx context.Context, pattern string, job JobFunc, name ...string) (*Entry, error)
AddSingleton 添加一个单例定时任务。 单例定时任务是指在同一时刻只能运行一个实例的任务。 可以使用唯一的 `name` 与定时任务绑定。 如果 `name` 已被使用,则返回错误。
func (*Cron) AddTimes ¶
func (c *Cron) AddTimes(ctx context.Context, pattern string, times int, job JobFunc, name ...string) (*Entry, error)
AddTimes 添加一个可运行指定次数的定时任务。 可以使用唯一的 `name` 与定时任务关联绑定。 如果 `name` 已被使用,则返回错误。
func (*Cron) DelayAdd ¶
func (c *Cron) DelayAdd(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)
DelayAdd 在 `delay` 时间后添加一个定时任务。
func (*Cron) DelayAddEntry ¶
func (c *Cron) DelayAddEntry(ctx context.Context, delay time.Duration, pattern string, job JobFunc, times int, isSingleton bool, name ...string)
DelayAddEntry 在 `delay` 时间后添加一个定时任务。
func (*Cron) DelayAddOnce ¶
func (c *Cron) DelayAddOnce(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)
DelayAddOnce在`delay`时间后添加一个定时任务。 这个定时任务只能运行一次。
func (*Cron) DelayAddSingleton ¶
func (c *Cron) DelayAddSingleton(ctx context.Context, delay time.Duration, pattern string, job JobFunc, name ...string)
DelayAddSingleton 在`delay`时间后添加一个单例定时任务。
func (*Cron) DelayAddTimes ¶
func (c *Cron) DelayAddTimes(ctx context.Context, delay time.Duration, pattern string, times int, job JobFunc, name ...string)
DelayAddTimes 在 `delay` 时间后添加一个定时任务。 此定时任务可以运行指定次数。
type Entry ¶
type Entry struct { Name string // Entry name. Job JobFunc `json:"-"` // 回调函数。 Time time.Time // Registered time. // contains filtered or unexported fields }
Entry 是定时任务的入口。
func AddSingleton ¶
AddSingleton 添加单例定时任务到默认的cron对象。 单例定时任务是指在同一时间只能运行一个实例的任务。 可以通过唯一的`name`与定时任务关联绑定。 如果`name`已经被使用,则返回错误。
func AddTimes ¶
func AddTimes(ctx context.Context, pattern string, times int, job JobFunc, name ...string) (*Entry, error)
AddTimes 向默认的 cron 对象添加一个可运行指定次数的定时任务。 可以为定时任务绑定一个唯一的 `name`。 如果 `name` 已经被使用,将会返回错误。
func (*Entry) SetSingleton ¶
SetSingleton 设置入口以单例模式运行。