Documentation
¶
Overview ¶
Package cron parses cron schedules and computes their next run: five fields (minute hour day-of-month month day-of-week), the descriptors @yearly, @monthly, @weekly, @daily, @hourly and @every <duration>, and a CRON_TZ= prefix naming the time zone the fields are read in.
s, err := cron.Parse("CRON_TZ=Africa/Dar_es_Salaam 0 7 * * 1-5")
next := s.Next(time.Now()) // 07:00 in Dar es Salaam, the next weekday
web schedules @web.Cron functions with it; it has no dependencies.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock interface {
Now() time.Time
// NewTimer fires once, d from now.
NewTimer(d time.Duration) Timer
}
Clock is the time a scheduler runs by: the real one, or a virtual one in tests (crontest.Clock).
var RealClock Clock = realClock{}
RealClock is the system's clock.
type Every ¶
Every runs every d, at the multiples of d counted from a fixed origin (time.Time's zero), so every process — every replica, every restart — agrees on the ticks: @every 30s runs at :00 and :30 of each minute.
type Schedule ¶
type Schedule interface {
// Next is the first run strictly after t; the zero time when there is
// none.
Next(t time.Time) time.Time
}
Schedule says when a job runs next.
func Parse ¶
Parse reads a schedule:
*/5 * * * * every five minutes 0 7 * * 1-5 07:00 on weekdays 30 2 1,15 * * 02:30 on the 1st and the 15th 0 0 * JAN,JUL SUN midnight on Sundays of January and July @hourly, @daily (@midnight), @weekly, @monthly, @yearly (@annually) @every 90s every 90 seconds (see Every) CRON_TZ=Europe/Paris 0 9 * * * the fields read in that zone
A field is *, a value, a range a-b, a list a,b,c, and each with a step /n; months and days of the week also by name (JAN, MON), and Sunday is 0 or 7. When both the day of the month and the day of the week are restricted, a day matching either runs (cron's rule). Without CRON_TZ (or TZ=) the fields are read in the time zone of the time Next is given.