clockwerk

package module
v0.0.0-...-354c9bd Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 1 Imported by: 8

README

clockwerk

Build Status   Coverage Status   Go Report Card   GoDoc

Job Scheduling Library

clockwerk allows you to schedule periodic jobs using a simple, fluent syntax.

Usage

go get github.com/onatm/clockwerk
package main

import (
  "fmt"
  "time"
  "github.com/onatm/clockwerk"
)

type DummyJob struct{}

func (d DummyJob) Run() {
  fmt.Println("Every 30 seconds")
}

func main() {
  var job DummyJob
  c := clockwerk.New()
  c.Every(30 * time.Second).Do(job)
  c.Start()
}

Documentation

Overview

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clockwerk

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

func New() *Clockwerk

New returns a new Clockwerk job runner.

func (*Clockwerk) Every

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

Every schedules a new Entry and returns it.

func (*Clockwerk) Start

func (c *Clockwerk) Start()

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

func (*Clockwerk) Stop

func (c *Clockwerk) Stop()

Stop the Clockwerk if it is running.

type Entry

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

func (e *Entry) Do(job Job)

Do adds a Job to the Entry.

type Job

type Job interface {
	Run()
}

Job is an interface for added jobs.

Jump to

Keyboard shortcuts

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