cron
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
package schedule provides utilities for managing template and workspaceautostart and autostop schedules. This includes utilities for parsing anddeserializing cron-style expressions.
Index¶
- type Schedule
- func (s Schedule) Cron() string
- func (s Schedule) DaysOfWeek() string
- func (s Schedule) Humanize() string
- func (s Schedule) Location() *time.Location
- func (s Schedule) Min() time.Duration
- func (s Schedule) Next(t time.Time) time.Time
- func (s Schedule) String() string
- func (s Schedule) Time() string
- func (s Schedule) TimeParsed() time.Time
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
This section is empty.
Types¶
typeSchedule¶
type Schedule struct {// contains filtered or unexported fields}
Schedule represents a cron schedule.It's essentially a wrapper for robfig/cron/v3 that has additionalconvenience methods.
funcDaily¶
Daily parses a Schedule from spec scoped to a recurring daily event.Spec consists of the following space-delimited fields, in the following order:- timezone e.g. CRON_TZ=US/Central (optional)- minutes of hour e.g. 30 (required)- hour of day e.g. 9 (required)- day of month (must be *)- month (must be *)- day of week (must be *)
Example Usage:
local_sched, _ := cron.Weekly("59 23 * * *")fmt.Println(sched.Next(time.Now().Format(time.RFC3339)))// Output: 2022-04-04T23:59:00Zus_sched, _ := cron.Weekly("CRON_TZ=US/Central 30 9 * * *")fmt.Println(sched.Next(time.Now()).Format(time.RFC3339))// Output: 2022-04-04T14:30:00Z
funcWeekly¶
Weekly parses a Schedule from spec scoped to a recurring weekly event.Spec consists of the following space-delimited fields, in the following order:- timezone e.g. CRON_TZ=US/Central (optional)- minutes of hour e.g. 30 (required)- hour of day e.g. 9 (required)- day of month (must be *)- month (must be *)- day of week e.g. 1 (required)
Example Usage:
local_sched, _ := cron.Weekly("59 23 *")fmt.Println(sched.Next(time.Now().Format(time.RFC3339)))// Output: 2022-04-04T23:59:00Zus_sched, _ := cron.Weekly("CRON_TZ=US/Central 30 9 1-5")fmt.Println(sched.Next(time.Now()).Format(time.RFC3339))// Output: 2022-04-04T14:30:00Z
func (Schedule)Cron¶
Cron returns the cron spec for the schedule with the leading CRON_TZstripped, if present.
func (Schedule)DaysOfWeek¶
DaysOfWeek returns a humanized form of the day-of-week field.
func (Schedule)Humanize¶added inv2.4.0
Humanize returns a slightly more human-friendly representation of theschedule.
func (Schedule)Min¶
Min returns the minimum duration of the schedule.This is calculated as follows:
- Let t(0) be a given point in time (1970-01-01T01:01:01Z00:00)
- Let t(max) be 168 hours after t(0).
- Let t(1) be the next scheduled time after t(0).
- Let t(n) be the next scheduled time after t(n-1).
- Then, the minimum duration of s d(min)= min( t(n) - t(n-1) ∀ n ∈ N, t(n) < t(max) )
func (Schedule)String¶
String serializes the schedule to its original format.The leading CRON_TZ is maintained.
func (Schedule)TimeParsed¶added inv2.2.0
TimeParsed returns the parsed time.Time of the minute and hour fields. If thetime cannot be represented in a valid time.Time, a zero time is returned.