clockwerk: Index | Files

package clockwerk

import ""

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


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)
// Funcs are invoked in their own goroutine, asynchronously.
c.Stop()  // Stop the scheduler (does not stop any jobs already running).


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 {

Job is an interface for added jobs.

Package clockwerk imports 1 packages (graph). Updated 2020-01-06. Refresh now. Tools for package owners.