periodic

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Func added in v0.6.0

type Func struct {
	// Task is the function that is executed on Run.
	Task func(context.Context)
	// TaskName is the name returned by Name,
	TaskName string
}

Func implements the Task interface.

func (Func) Name added in v0.6.0

func (f Func) Name() string

Name returns the task name.

func (Func) Run added in v0.6.0

func (f Func) Run(ctx context.Context)

Run runs the task function.

type Runner

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

Runner runs a task periodically.

func Start

func Start(task Task, period, timeout time.Duration) *Runner

Start creates and starts a new Runner to run the given task peridiocally. The timeout is used for the context timeout of the task. The timeout can be larger than the periodicity of the task. That means if a tasks takes a long time it will be immediately retriggered.

func (*Runner) Kill

func (r *Runner) Kill()

Kill is like stop but it also cancels the context of the current running method.

func (*Runner) Stop

func (r *Runner) Stop()

Stop stops the periodic execution of the Runner. If the task is currently running this method will block until it is done.

func (*Runner) TriggerRun

func (r *Runner) TriggerRun()

TriggerRun triggers the periodic task to run now. This does not impact the normal periodicity of this task. That means if the periodicity is 5m and you call TriggerNow() after 2 minutes, the next execution will be in 3 minutes.

The method blocks until either the triggered run was started or the runner was stopped, in which case the triggered run will not be executed.

type Task

type Task interface {
	// Run executes the task once, it should return within the context's timeout.
	Run(context.Context)
	// Name returns the task's name for use in metrics and tracing. Each
	// successive call should return the same value as the first call. Names
	// must only contain [a-z] and _ characters.
	Name() string
}

A Task that has to be periodically executed.

Directories

Path Synopsis
internal
metrics/mock_metrics
Package mock_metrics is a generated GoMock package.
Package mock_metrics is a generated GoMock package.

Jump to

Keyboard shortcuts

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