Documentation
¶
Index ¶
- type Chain
- type ConstantDelaySchedule
- type Cron
- func (c *Cron) AddFunc(spec string, cmd func()) (EntryID, error)
- func (c *Cron) AddJob(spec string, cmd Job) (EntryID, error)
- func (c *Cron) Entries() []Entry
- func (c *Cron) Entry(id EntryID) Entry
- func (c *Cron) Location() *time.Location
- func (c *Cron) Remove(id EntryID)
- func (c *Cron) Run()
- func (c *Cron) Schedule(schedule Schedule, cmd Job) EntryID
- func (c *Cron) Start()
- func (c *Cron) Stop(ctx context.Context) context.Context
- type Entry
- type EntryID
- type FuncJob
- type Job
- type JobWrapper
- type Option
- type ParseOption
- type Parser
- type Schedule
- type ScheduleParser
- type SpecSchedule
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct {
// contains filtered or unexported fields
}
Chain 是一个 JobWrappers 序列,用于装饰提交的任务。 cross-cutting behaviors like logging or synchronization.
type ConstantDelaySchedule ¶
ConstantDelaySchedule 表示一个简单的循环占空比,例如 “每 5 分钟”。 它不支持比每秒一次更频繁的任务。
func Every ¶
func Every(duration time.Duration) ConstantDelaySchedule
Every 返回每个持续时间激活一次的 crontab 计划。 不支持小于一秒的延迟(将四舍五入到 1 秒)。 任何小于秒的字段都会被截断。
type Cron ¶
type Cron struct {
// contains filtered or unexported fields
}
Cron 跟踪任意数量的条目,调用调度指定的关联函数。 Cron 可以启动、停止,并且可以在运行时检查条目。
func New ¶
New 返回由给定选项修改的新 Cron 任务运行器。
可用设置
TimeZone 描述: 解释时间表的时区 默认: time.Local Parser 描述: Parser 将 cron 规范字符串转换为 cron.Schedules。 默认: 接受此规范:https://en.wikipedia.org/wiki/Cron Chain 描述: 以自定义行为包装提交任务。 默认: 恢复 panic 并将其记录到标准错误 stderr。
请参阅“cron.With*”以修改默认行为。
func (*Cron) AddFunc ¶
AddFunc 向 Cron 添加一个函数,按给定的时间表运行。 使用此 Cron 实例的时区作为默认值解析规范。 返回一个不透明的 ID,以后可以使用它来移除它。
type Entry ¶
type Entry struct { // ID 此条目的 cron 分配的 ID,可用于查找快照或删除它。 ID EntryID // Schedule 运行此任务的计划。 Schedule Schedule // Next 任务将运行的时间,或者如果 Cron 尚未启动或此条目的计划无法满足,则为零时间。 Next time.Time // Prev 上次运行此作业的时间,如果从未运行,则为零时间。 Prev time.Time // WrappedJob 激活调度时要运行的任务。 WrappedJob Job // Job 提交给 cron 的任务。 Job Job }
Entry 由一个时间表和在该时间表上执行的函数组成。
type JobWrapper ¶
JobWrapper 用一些行为装饰指定的 Job。
func DelayIfStillRunning ¶
func DelayIfStillRunning() JobWrapper
DelayIfStillRunning 序列化作业,延迟后续运行,直到前一个完成。延迟超过一分钟后运行的作业会在信息中记录延迟。
func SkipIfStillRunning ¶
func SkipIfStillRunning() JobWrapper
SkipIfStillRunning 如果先前的调用仍在运行,则跳过对 Job 的调用。它记录跳转到信息级别的给定记录器。
type Option ¶
type Option func(*Cron)
Option 表示对 Cron 的默认行为的修改。
func WithChain ¶
func WithChain(wrappers ...JobWrapper) Option
WithChain 指定要应用于添加到此 cron 的所有任务的包装器。 有关提供的包装器,请参阅此包中的 Chain* 函数。
type ParseOption ¶
type ParseOption int
ParseOption 用于创建解析器的配置选项。 大多数选项指定应包含哪些字段,而其他选项则启用功能。 如果未包含字段,则解析器将采用默认值。 这些选项不会更改解析的顺序字段。
const ( Second ParseOption = 1 << iota // 秒,默认 0 SecondOptional // 可选秒,默认0 Minute // 分,默认 0 Hour // 时,默认 0 Dom // 日,默认 * Month // 月,默认 * Dow // 周,默认 * DowOptional // 可选周,默认 * Descriptor // 允许使用 @monthly、@weekly 等描述符。 )
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser 可以配置的自定义解析器。
func NewParser ¶
func NewParser(options ParseOption) Parser
NewParser 使用自定义选项创建解析器。
如果给出了多个 Optional,它会出现 panic,因为通常无法正确推断提供或缺少哪个可选。
例子
// 没有描述符的标准解析器 specParser := NewParser(Minute | Hour | Dom | Month | Dow) sched, err := specParser.Parse("0 0 15 */3 *") // 同上,只是不包括时间字段 specParser := NewParser(Dom | Month | Dow) sched, err := specParser.Parse("15 */3 *") // 同上,只是使 Dow 可选 specParser := NewParser(Dom | Month | DowOptional) sched, err := specParser.Parse("15 */3")
type Schedule ¶
type Schedule interface { // Next 返回下一个激活时间,晚于给定时间。 // Next 最初调用,然后每次运行作业时调用。 Next(time.Time) time.Time }
Schedule 描述一个任务的工作周期。
func ParseStandard ¶
ParseStandard 返回代表指定的新 crontab 计划。 标准规范 (https://en.wikipedia.org/wiki/Cron)。 它需要 5 个条目,依次代表:分钟、小时、月中的某天、月和周中的某天。 如果规范无效,它会返回描述性错误。
它接受 - 标准 crontab 规范,例如 “* * * * ?” - 描述符,例如 “@midnight”、“@每 1 小时 30 分”
type ScheduleParser ¶
ScheduleParser 返回 Schedule 的调度规范解析器的接口。
type SpecSchedule ¶
type SpecSchedule struct {
Second, Minute, Hour, Dom, Month, Dow uint64
// 覆盖此计划的时区。
Location *time.Location
}
SpecSchedule 根据传统的 crontab 规范指定占空比(到第二个粒度)。 它最初被计算并存储为位集。