git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/cron/README.md (about)

     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  
     6  Cron V3 has been released!
     7  
     8  To download the specific tagged release, run:
     9  ```bash
    10  go get git.sr.ht/~pingoo/stdx/cron@v3.0.0
    11  ```
    12  Import it in your program as:
    13  ```go
    14  import "git.sr.ht/~pingoo/stdx/cron"
    15  ```
    16  It requires Go 1.11 or later due to usage of Go Modules.
    17  
    18  Refer to the documentation here:
    19  http://godoc.org/github.com/robfig/cron
    20  
    21  The rest of this document describes the the advances in v3 and a list of
    22  breaking changes for users that wish to upgrade from an earlier version.
    23  
    24  ## Upgrading to v3 (June 2019)
    25  
    26  cron v3 is a major upgrade to the library that addresses all outstanding bugs,
    27  feature requests, and rough edges. It is based on a merge of master which
    28  contains various fixes to issues found over the years and the v2 branch which
    29  contains some backwards-incompatible features like the ability to remove cron
    30  jobs. In addition, v3 adds support for Go Modules, cleans up rough edges like
    31  the timezone support, and fixes a number of bugs.
    32  
    33  New features:
    34  
    35  - Support for Go modules. Callers must now import this library as
    36    `git.sr.ht/~pingoo/stdx/cron`, 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  
    60  It 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  ```go
    69  // Seconds field, required
    70  cron.New(cron.WithSeconds())
    71  
    72  // Seconds field, optional
    73  cron.New(cron.WithParser(cron.NewParser(
    74  	cron.SecondOptional | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor,
    75  )))
    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  ```go
    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  ```go
   106  cron.New(
   107    cron.WithLogger(cron.VerbosePrintfLogger(logger)))
   108  ```
   109  
   110  ### Background - Cron spec format
   111  
   112  There 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  
   123  The original version of this package included an optional "seconds" field, which
   124  made it incompatible with both of these formats. Now, the "standard" format is
   125  the default format accepted, and the Quartz format is opt-in.