Back to

package gron

v0.0.0 (e78485a)
Latest Go to latest
Published: Jun 21, 2016 | License: MIT | Module:


type AtSchedule

type AtSchedule interface {
	At(t string) Schedule

AtSchedule extends Schedule by enabling periodic-interval & time-specific setup

func Every

func Every(p time.Duration) AtSchedule

Every returns a Schedule reoccurs every period p, p must be at least time.Second.

type Cron

type Cron struct {
	// contains filtered or unexported fields

Cron provides a convenient interface for scheduling job such as to clean-up database entry every month.

Cron keeps track of any number of entries, invoking the associated func as specified by the schedule. It may also be started, stopped and the entries may be inspected.

func New

func New() *Cron

New instantiates new Cron instant c.

func (*Cron) Add

func (c *Cron) Add(s Schedule, j Job)

Add appends schedule, job to entries.

if cron instant is not running, adding to entries is trivial. otherwise, to prevent data-race, adds through channel.

func (*Cron) AddFunc

func (c *Cron) AddFunc(s Schedule, j func())

AddFunc registers the Job function for the given Schedule.

func (Cron) Entries

func (c Cron) Entries() []*Entry

Entries returns cron etn

func (*Cron) Start

func (c *Cron) Start()

Start signals cron instant c to get up and running.

func (*Cron) Stop

func (c *Cron) Stop()

Stop halts cron instant c from running.

type Entry

type Entry struct {
	Schedule Schedule
	Job      Job

	// the next time the job will run. This is zero time if Cron has not been
	// started or invalid schedule.
	Next time.Time

	// the last time the job was run. This is zero time if the job has not been
	// run.
	Prev time.Time

Entry consists of a schedule and the job to be executed on that schedule.

type Job

type Job interface {

Job is the interface that wraps the basic Run method.

Run executes the underlying func.

type JobFunc

type JobFunc func()

JobFunc is an adapter to allow the use of ordinary functions as gron.Job If f is a function with the appropriate signature, JobFunc(f) is a handler that calls f.

todo: possibly func with params? maybe not needed.

func (JobFunc) Run

func (j JobFunc) Run()

Run calls j()

type Schedule

type Schedule interface {
	Next(t time.Time) time.Time

Schedule is the interface that wraps the basic Next method.

Next deduces next occurring time based on t and underlying states.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier