periodic

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Overview

periodic runs periodic tasks. Tasks can be registered to a Scheduler which may or may not be "ticking", i.e. running its tasks.

Index

Constants

View Source
const (
	Hourly      = 1 * time.Hour
	Daily       = 24 * time.Hour
	TwiceDaily  = Daily / 2
	ThriceDaily = Daily / 3

	// TaskTime is a key for a context.Context where the starting time of
	// the current request is stored.
	TaskTime = contextKey(iota)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Scheduler

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

Scheduler runs registered periodic tasks. Its zero value is a valid Scheduler that doesn't tick and has no registered task. It may be used in parallel.

func (*Scheduler) Register

func (s *Scheduler) Register(t Task, p time.Duration, n string)

Register registers a Task to the Scheduler to be run at period p. If the Scheduler is ticking, the task starts ticking immediately.

func (*Scheduler) Start

func (s *Scheduler) Start()

Start starts a Scheduler. Starting an already started scheduler is functionally a noop, though an error will be logged.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop stops a Scheduler. Stopping an already stopped scheduler is functionally a noop, though an error will be logged.

func (*Scheduler) Ticking

func (s *Scheduler) Ticking() bool

Ticking returns whether the Scheduler is currently ticking.

type Task

type Task func(context.Context) error

Task is a task that can be scheduled.

Jump to

Keyboard shortcuts

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