clockwerk: github.com/onatm/clockwerk Index | Files

package clockwerk

import "github.com/onatm/clockwerk"

Package clockwerk implements an in-process scheduler for periodic jobs.

Usage

Callers may register Jobs to be invoked on a given schedule. Clockwerk will run them in their own goroutines.

type DummyJob struct{}

func (d DummyJob) Run() {
  fmt.Println("Every 30 seconds")
}
...
var job DummyJob
c := clockwerk.New()
c.Every(30 * time.Second).Do(job)
c.Start()
...
// Funcs are invoked in their own goroutine, asynchronously.
...
c.Stop()  // Stop the scheduler (does not stop any jobs already running).

Index

Package Files

clockwerk.go doc.go

type Clockwerk Uses

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

Clockwerk keeps track of any number of entries, invoking associated Job's Run method as specified by the schedule.

func New Uses

func New() *Clockwerk

New returns a new Clockwerk job runner.

func (*Clockwerk) Every Uses

func (c *Clockwerk) Every(period time.Duration) *Entry

Every schedules a new Entry and returns it.

func (*Clockwerk) Start Uses

func (c *Clockwerk) Start()

Start the Clockwerk in its own go-routine, or no-op if already started.

func (*Clockwerk) Stop Uses

func (c *Clockwerk) Stop()

Stop the Clockwerk if it is running.

type Entry Uses

type Entry struct {
    Period time.Duration
    Next   time.Time
    Prev   time.Time
    Job    Job
}

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

func (*Entry) Do Uses

func (e *Entry) Do(job Job)

Do adds a Job to the Entry.

type Job Uses

type Job interface {
    Run()
}

Job is an interface for added jobs.

Package clockwerk imports 1 packages (graph). Updated 2017-04-16. Refresh now. Tools for package owners.