• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.gitignoreH A D04-Jan-2020252

.travis.ymlH A D04-Jan-202013

LICENSEH A D04-Jan-20201.1 KiB

README.mdH A D04-Jan-20205.1 KiB

chain.goH A D04-Jan-20202.1 KiB

chain_test.goH A D04-Jan-20205.9 KiB

constantdelay.goH A D04-Jan-2020934

constantdelay_test.goH A D04-Jan-20201.9 KiB

cron.goH A D04-Jan-20208.6 KiB

cron_test.goH A D04-Jan-202016.2 KiB

doc.goH A D04-Jan-20208.1 KiB

go.modH A D04-Jan-202042

logger.goH A D04-Jan-20202.5 KiB

option.goH A D04-Jan-20201.1 KiB

option_test.goH A D04-Jan-2020867

parser.goH A D04-Jan-202011.1 KiB

parser_test.goH A D04-Jan-20209.7 KiB

spec.goH A D04-Jan-20204.5 KiB

spec_test.goH A D04-Jan-202010.7 KiB

README.md

1[![GoDoc](http://godoc.org/github.com/robfig/cron?status.png)](http://godoc.org/github.com/robfig/cron)
2[![Build Status](https://travis-ci.org/robfig/cron.svg?branch=master)](https://travis-ci.org/robfig/cron)
3
4# cron
5
6Cron V3 has been released!
7
8To download the specific tagged release, run:
9
10	go get github.com/robfig/cron/v3@v3.0.0
11
12Import it in your program as:
13
14	import "github.com/robfig/cron/v3"
15
16It requires Go 1.11 or later due to usage of Go Modules.
17
18Refer to the documentation here:
19http://godoc.org/github.com/robfig/cron
20
21The rest of this document describes the the advances in v3 and a list of
22breaking changes for users that wish to upgrade from an earlier version.
23
24## Upgrading to v3 (June 2019)
25
26cron v3 is a major upgrade to the library that addresses all outstanding bugs,
27feature requests, and rough edges. It is based on a merge of master which
28contains various fixes to issues found over the years and the v2 branch which
29contains some backwards-incompatible features like the ability to remove cron
30jobs. In addition, v3 adds support for Go Modules, cleans up rough edges like
31the timezone support, and fixes a number of bugs.
32
33New features:
34
35- Support for Go modules. Callers must now import this library as
36  `github.com/robfig/cron/v3`, instead of `gopkg.in/...`
37
38- Fixed bugs:
39  - 0f01e6b parser: fix combining of Dow and Dom (#70)
40  - dbf3220 adjust times when rolling the clock forward to handle non-existent midnight (#157)
41  - eeecf15 spec_test.go: ensure an error is returned on 0 increment (#144)
42  - 70971dc cron.Entries(): update request for snapshot to include a reply channel (#97)
43  - 1cba5e6 cron: fix: removing a job causes the next scheduled job to run too late (#206)
44
45- Standard cron spec parsing by default (first field is "minute"), with an easy
46  way to opt into the seconds field (quartz-compatible). Although, note that the
47  year field (optional in Quartz) is not supported.
48
49- Extensible, key/value logging via an interface that complies with
50  the https://github.com/go-logr/logr project.
51
52- The new Chain & JobWrapper types allow you to install "interceptors" to add
53  cross-cutting behavior like the following:
54  - Recover any panics from jobs
55  - Delay a job's execution if the previous run hasn't completed yet
56  - Skip a job's execution if the previous run hasn't completed yet
57  - Log each job's invocations
58  - Notification when jobs are completed
59
60It is backwards incompatible with both v1 and v2. These updates are required:
61
62- The v1 branch accepted an optional seconds field at the beginning of the cron
63  spec. This is non-standard and has led to a lot of confusion. The new default
64  parser conforms to the standard as described by [the Cron wikipedia page].
65
66  UPDATING: To retain the old behavior, construct your Cron with a custom
67  parser:
68
69      // Seconds field, required
70      cron.New(cron.WithSeconds())
71
72      // Seconds field, optional
73      cron.New(
74          cron.WithParser(
75              cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor))
76
77- The Cron type now accepts functional options on construction rather than the
78  previous ad-hoc behavior modification mechanisms (setting a field, calling a setter).
79
80  UPDATING: Code that sets Cron.ErrorLogger or calls Cron.SetLocation must be
81  updated to provide those values on construction.
82
83- CRON_TZ is now the recommended way to specify the timezone of a single
84  schedule, which is sanctioned by the specification. The legacy "TZ=" prefix
85  will continue to be supported since it is unambiguous and easy to do so.
86
87  UPDATING: No update is required.
88
89- By default, cron will no longer recover panics in jobs that it runs.
90  Recovering can be surprising (see issue #192) and seems to be at odds with
91  typical behavior of libraries. Relatedly, the `cron.WithPanicLogger` option
92  has been removed to accommodate the more general JobWrapper type.
93
94  UPDATING: To opt into panic recovery and configure the panic logger:
95
96      cron.New(cron.WithChain(
97          cron.Recover(logger),  // or use cron.DefaultLogger
98      ))
99
100- In adding support for https://github.com/go-logr/logr, `cron.WithVerboseLogger` was
101  removed, since it is duplicative with the leveled logging.
102
103  UPDATING: Callers should use `WithLogger` and specify a logger that does not
104  discard `Info` logs. For convenience, one is provided that wraps `*log.Logger`:
105
106      cron.New(
107          cron.WithLogger(cron.VerbosePrintfLogger(logger)))
108
109
110### Background - Cron spec format
111
112There are two cron spec formats in common usage:
113
114- The "standard" cron format, described on [the Cron wikipedia page] and used by
115  the cron Linux system utility.
116
117- The cron format used by [the Quartz Scheduler], commonly used for scheduled
118  jobs in Java software
119
120[the Cron wikipedia page]: https://en.wikipedia.org/wiki/Cron
121[the Quartz Scheduler]: http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/tutorial-lesson-06.html
122
123The original version of this package included an optional "seconds" field, which
124made it incompatible with both of these formats. Now, the "standard" format is
125the default format accepted, and the Quartz format is opt-in.
126