原文地址:robfig/cron: a cron library for go (github.com)
Upgrading to v3 (June 2019)
cron v3 is a major upgrade to the library(平时为图书馆,在计算机专业术语中为软件库,此处也就是指cron库) that addresses(名词地址,动词演讲解说,出发解决,处理;此处翻译为解决处理) all outstanding(杰出的,优秀的;显著的,突出的;未解决的,未完成的;(款项)未支付的,未结清的;此处译为未解决的,未完成的) bugs, feature requests(Feature Phone译为功能型手机功能手机特色电话机,requests平时翻译为要求请求,计算机术语为要求计算机提供信息或执行另一任务的指令 , and rough edges(rough 为粗糙的,edge为边缘,也是就粗糙的边缘,意思就是未完善的地方)
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. (它是基于一个主分支和v2分支的合并,主分支包含了大量的对于过去多年来发现的问题的修复,v2分支则是包含一些向下不兼容功能例如去删除corn作业的能力(暗含v3支持了删除corn的功能)。 除此之外,v3支持Go模块,清理解决了一些不完善的地方例如时区支持功能,并且修复了大量的bug)
New features: 新特性
-
Support for Go modules. Callers(使用者) must now import this library as github.com/robfig/cron/v3, instead of gopkg.in/...
-
Fixed bugs: 被修复的bug
-
0f01e6b parser: fix combining(结合) of Dow and Dom (#70)
-
dbf3220 adjust times when rolling the clock forward to handle non-existent midnight (#157) (调整时间时,滚动时钟,以处理不存在的午夜)
-
eeecf15 spec_test.go: ensure an error is returned on 0 increment (#144)(确保每增加0就返回一个错误)
-
70971dc cron.Entries(): update request for snapshot(快照) to include a reply channel (#97)(更新快照的请求,使其包含一个应答通道)
-
1cba5e6 cron: fix: removing a job causes the next scheduled job to run too late (#206)(删除作业会导致下一个计划作业运行得太晚)
-
-
Standard cron spec parsing by default (first field(计算机专业术语:字段) is "minute"), with an easy way to opt into the seconds field (quartz-compatible). Although, note that the year field (optional in Quartz) is not supported. 标准的定时库定时规则会被默认解析为第一个字段是分钟,有一个简单的方式去选择到秒字段(Quartz兼容)。但是需要注意,不支持年份字段(在Quartz中是可选的)
-
Extensible, key/value logging via an interface that complies with(遵循,遵守) the GitHub - go-logr/logr: A simple logging interface for Go project. (可扩展的键值日志通过一个接口实现,这个接口是基于GitHub - go-logr/logr: A simple logging interface for Go项目)
-
The new Chain & JobWrapper types allow you to install "interceptors" to add cross-cutting behavior like the following:(新的Chain和JobWrapper类型允许你安装“拦截器”来添加横切行为,如下所示:)
-
Recover any panics from jobs(修复任何jobs的崩溃)
-
Delay(延迟) a job's execution(执行,实施) if the previous run hasn't completed yet (此刻) (如果一个先前的执行过程此刻还没有完成的话,则延迟一个job的执行)
-
Skip a job's execution if the previous run hasn't completed yet (如果一个先前的执行过程此刻还没有被完成的话,可以跳过一个job的执行)
-
Log each job's invocations(求助,祈祷;计算机术语:调用)(记录每一个工作的执行)
-
Notification (通告,通知)when jobs are completed (当任务被完成时发送通告)
-
It is backwards(adv) incompatible with both v1 and v2. These updates are required: (v3向下不兼容v1和v2,下面的更新是必须的)
-
The v1 branch accepted(接受) an optional seconds field at the beginning of the cron spec. This is non-standard and has led to a lot of confusion(混淆,模糊不清). The new default parser(计算机术语:解析器) conforms to(符合,遵照,按照) the standard as(正如) described by the Cron wikipedia page.(v1分支在cron刚开始的定时规则字符中接受一个可选的秒级字段,这是一个不标准的行为并且会导致大量的模糊不清。v3的新的默认解析器按照一个正如维基百科页面描述的标准来解析)
UPDATING: To retain the old behavior(行为,计算机术语:特性,行为), construct(构建,组成) your Cron with a custom(习惯风俗,计算机术语:定制,自定义) parser
(更新:为了保留旧的功能,可以使用一个自定义的解析器去构建你的Cron)
// 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, )))
-
The Cron type now accepts functional options on construction rather than the previous ad-hoc(特定的,临时安排的) behavior modification(修改,修正) mechanisms(机制,机构) (setting a field, calling(计算机术语:调用,呼叫) a setter). (cron类型现在在构造过程中接受函数选项,而不是之前的特定的修改机制(设置字段,调用setter))
UPDATING: Code that sets Cron.ErrorLogger or calls Cron.SetLocation must be updated to provide those values on construction.(设置cron errorlogger或调用Cron-SetLocation的代码必须更新,以便在构造时提供这些值)
-
CRON_TZ is now the recommended way to specify(明确指出,具体说明,计算机术语:制定) the timezone of a single schedule, which is sanctioned(制裁,处罚,许可,批准,支持) by the specification(计算机术语:规格,规范,说明书). The legacy(传统,旧有,(软件或硬件)已过时但因使用范围广而难以替代的) "TZ=" prefix will continue to be supported since it is unambiguous(无歧义的) and easy to do so.(现在推荐使用CRON_TZ来指定单个时刻表的时区,这是规范所允许的。遗留的“TZ=”前缀将继续被支持,因为它是明确的,并且很容易这样做。)
UPDATING: No update is required. (更新:不需要更新。)
-
By default, cron will no longer recover panics in jobs that it runs. Recovering can be surprising (see issue #192) and seems to be at odds with typical behavior of libraries. Relatedly, the
cron.WithPanicLogger
option has been removed to accommodate the more general JobWrapper type.(默认情况下,cron将不再恢复其运行的作业中的恐慌。恢复可能会令人惊讶(参见issue #192),而且似乎与库的典型行为不一致。与此相关,cronWithPanicLogger选项已被删除,以适应更通用的JobWrapper类型。)UPDATING: To opt into panic recovery and configure(配置) the panic logger:(更新:选择崩溃恢复并配置紧急日志记录器:)
cron.New(cron.WithChain( cron.Recover(logger), // or use cron.DefaultLogger ))
Background - Cron spec format
There are two cron spec formats in common usage:
-
The "standard" cron format, described on the Cron wikipedia page and used by the cron Linux system utility(计算机术语:程序).
-
The cron format used by the Quartz Scheduler, commonly used for scheduled jobs in Java software
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.(这个包的原始版本包含一个可选的“seconds”字段,这使得它与这两种格式都不兼容。现在,“标准”格式是默认接受的格式,Quartz格式是可选择的)
-