cron

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 20, 2021 License: BSD-3-Clause Imports: 5 Imported by: 1

Documentation

Overview

Package cron provides functionality for parsing and running cron schedules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cron

type Cron struct {
	C <-chan time.Time // The channel on which events are delivered
	// contains filtered or unexported fields
}

A Cron holds a channel that delivers events based on the cron schedule.

func NewCron

func NewCron(sch Schedule, tz *time.Location) *Cron

NewCron returns a new Cron containing a channel that sends the time at every moment specified by the Schedule. The timezone the cron job is operating in must be specified. Stop Cron to release associated resources.

func (*Cron) Stop

func (c *Cron) Stop()

Stop turns off the cron job. After Stop, no more events will be sent. Stop does not close the channel, to prevent a read from the channel succeeding incorrectly.

type Schedule

type Schedule struct {
	// contains filtered or unexported fields
}

Schedule represents a cron schedule.

func ParseSchedule

func ParseSchedule(s string) (Schedule, error)

ParseSchedule parses a cron schedule, which is a space-separated list of five fields representing:

  • minutes: 0-59
  • hours: 0-23
  • days of month: 1-31
  • months: 1-12 or JAN-DEC
  • days of week: 0-6 or SUN-SAT

Each field may be a glob (e.g., "*"), representing the full range of values, or a comma-separated list, containing individual values (e.g., "JAN") or a dash-separated pair representing a range of values (e.g., "MON-FRI").

The following macros are permitted:

  • @yearly: "0 0 1 1 *"
  • @annually: "0 0 1 1 *"
  • @monthly: "0 0 1 * *"
  • @weekly: "0 0 * * 0"
  • @daily: "0 0 * * *"
  • @hourly: "0 * * * *"

A given timestamp is in the schedule if the associated fields of the timestamp matches each field specified in the schedule.

See https://wikipedia.org/wiki/cron

func (Schedule) NextAfter

func (s Schedule) NextAfter(t time.Time) time.Time

NextAfter returns the next scheduled event, relative to the specified t, taking into account t.Location. This returns the zero value if unable to determine the next scheduled event.

func (Schedule) String

func (s Schedule) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL