cron README

The project's README from github.com/robfig/cron. As one markdown file: README.md.

GoDoc Build Status

cron

Cron V3 has been released!

To download the specific tagged release, run:

go get github.com/robfig/cron/[email protected]

Import it in your program as:

import "github.com/robfig/cron/v3"

It requires Go 1.11 or later due to usage of Go Modules.

Refer to the documentation here: http://godoc.org/github.com/robfig/cron

The rest of this document describes the the advances in v3 and a list of breaking changes for users that wish to upgrade from an earlier version.

Upgrading to v3 (June 2019)

cron v3 is a major upgrade to the library that addresses all outstanding bugs, feature requests, and rough edges. It is based on a merge of master which contains various fixes to issues found over the years and the v2 branch which contains some backwards-incompatible features like the ability to remove cron jobs. In addition, v3 adds support for Go Modules, cleans up rough edges like the timezone support, and fixes a number of bugs.

New features:

It is backwards incompatible with both v1 and v2. These updates are required:

// Seconds field, required
cron.New(cron.WithSeconds())

// Seconds field, optional
cron.New(cron.WithParser(cron.NewParser(
	cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor,
)))
cron.New(cron.WithChain(
  cron.Recover(logger),  // or use cron.DefaultLogger
))
cron.New(
  cron.WithLogger(cron.VerbosePrintfLogger(logger)))

Background - Cron spec format

There are two cron spec formats in common usage:

The original version of this package included an optional "seconds" field, which made it incompatible with both of these formats. Now, the "standard" format is the default format accepted, and the Quartz format is opt-in.

cron (robfig/cron)

Searching Database…

14.2K ·GitHub
这是什么?这是一个 Go 库,实现了类 cron 的任务调度,让你可以在 Go 程序内部按计划运行函数,而不必依赖系统的 cron 守护进程。
这是一个独立的调度器应用,还是需要导入到我的代码里的东西?这是一个 Go 库,直接导入到你自己的程序中,不是单独的服务或可执行文件。
我该如何把它加到我的 Go 项目里?用 github.com/robfig/cron/v3 导入它,然后创建一个 Cron 实例,并用 cron 时间表达式字符串注册你的任务。
我需要特定的 Go 版本吗?需要,该库使用 Go Modules,因此要求 Go 1.11 或更高版本。
如果升级,我现有的 v1/v2 代码还能继续正常运行吗?不能。v3 与旧版本不兼容:它去掉了非标准的默认“秒”字段,改用函数式选项进行配置,并且默认不再捕获任务中的 panic。
谁会用这个?需要在进程内执行定时任务(周期性任务、维护任务、重复性工作流)、而不想调用操作系统 cron 的 Go 开发者。
默认使用哪种 cron 时间表达式格式?默认使用标准的五字段 cron 格式(分 时 日 月 周),与维基百科 Cron 页面中的描述一致,而不是 v1 中非标准的秒在前格式。
我能使用带秒的 Quartz 风格 cron 表达式吗?可以,通过自定义解析器可以选择启用兼容 Quartz 的秒字段解析,但不支持 Quartz 可选的年份字段。
Chain/JobWrapper 功能是做什么用的?Chain 和 JobWrapper 让你可以用通用行为包装任务,例如 panic 恢复、跳过或延迟重叠的运行、记录每次调用的日志,以及完成通知。
如何为某个特定调度设置时区?在 cron 时间表达式前加上 CRON_TZ= 前缀(旧的 TZ= 前缀仍然支持),即可让该调度在指定时区中运行。
What are similar projects?bull, rq, crawlab, xxl-job, celery, tork, temporal, gjson
Creator
robfig
Size
0.2 MB
Stars
14.2K
Updated
CommitJan 06
Age
14y
Commits · 90 Days