up

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 License: Apache-2.0 Imports: 2 Imported by: 73

Documentation

Overview

Package up is used to run a function for some duration. If a new function is added while a previous run is still ongoing, nothing new will be executed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Func

type Func func() error

Func is used to determine if a target is alive. If so this function must return nil.

type Probe

type Probe struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Probe is used to run a single Func until it returns true (indicating a target is healthy). If an Func is already in progress no new one will be added, i.e. there is always a maximum of 1 checks in flight.

There is a tradeoff to be made in figuring out quickly that an upstream is healthy and not doing to much work (sending queries) to find that out. Having some kind of exp. backoff here won't help much, because you don't won't to backoff too much. You then also need random queries to be perfomed every so often to quickly detect a working upstream. In the end we just send a query every 0.5 second to check the upstream. This hopefully strikes a balance between getting information about the upstream state quickly and not doing too much work. Note that 0.5s is still an eternity in DNS, so we may actually want to shorten it.

func New

func New() *Probe

New returns a pointer to an initialized Probe.

func (*Probe) Do

func (p *Probe) Do(f Func)

Do will probe target, if a probe is already in progress this is a noop.

func (*Probe) Start

func (p *Probe) Start(interval time.Duration)

Start will initialize the probe manager, after which probes can be initiated with Do.

func (*Probe) Stop

func (p *Probe) Stop()

Stop stops the probing.

Jump to

Keyboard shortcuts

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