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)

scheduling
Searching Database…

14.2K ·GitHub
What is this?It is a Go library that implements cron-style job scheduling, letting you run functions on a schedule inside a Go program instead of relying on the system cron daemon.
Is this a standalone scheduler app or something I import into my code?It is a Go library you import directly into your own program, not a separate service or binary.
How do I add it to my Go project?Import it as github.com/robfig/cron/v3 and create a Cron instance to register your jobs with a cron spec string.
Do I need a specific Go version?Yes, Go 1.11 or later is required because the library uses Go Modules.
Will my existing v1/v2 code just keep working if I upgrade?No, v3 is backwards-incompatible: it drops the non-standard default 'seconds' field, switches to functional options for configuration, and no longer recovers panics in jobs by default.
Who would use this?Go developers who need in-process scheduled tasks (periodic jobs, maintenance tasks, recurring workflows) without shelling out to the OS cron.
What cron spec format does it use by default?It uses the standard five-field cron format (minute hour day-of-month month day-of-week) as described on the Cron Wikipedia page, rather than the non-standard seconds-first format from v1.
Can I use Quartz-style cron expressions with seconds?Yes, Quartz-compatible seconds-field parsing is opt-in via a custom parser, though the optional Quartz year field is not supported.
What is the Chain/JobWrapper feature for?Chain and JobWrapper let you wrap jobs with cross-cutting behavior like panic recovery, skipping or delaying overlapping runs, logging invocations, and completion notifications.
How do I set a timezone for a specific schedule?Prefix the cron spec with CRON_TZ= (the legacy TZ= prefix is still supported too) to run that schedule in a specific timezone.
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