nanny

package
v0.0.0-...-30c4d99 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2018 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrorFunc

type ErrorFunc func(error)

ErrorFunc is a function that will be called by Nanny if there was any error during notifier.Notify call.

type Nanny

type Nanny struct {
	Name string // Nanny's name.
	// Function that will be called when notifier.Notify returns error.
	// If not specified, uses defaultErrorFunc.
	ErrorFunc ErrorFunc
	// contains filtered or unexported fields
}

Nanny represents the main functionality with its `Handle` func. There should be only one nanny per process.

func (*Nanny) GetTimer

func (n *Nanny) GetTimer(name string) *Timer

GetTimer returns time.Timer when given program name is already registered or nil.

func (*Nanny) GetTimers

func (n *Nanny) GetTimers() []*Timer

GetTimers returns a slice of currently open timers

func (*Nanny) Handle

func (n *Nanny) Handle(s Signal) error

Handle creates new timer within `Nanny`, which calls `signal.Notifier.Notify()` if there is no signal within NextSignal + MaxDeviation.

func (*Nanny) SetTimer

func (n *Nanny) SetTimer(name string, timer *Timer)

SetTimer sets new timer for given program name.

type Signal

type Signal struct {
	// Name of program being monitored.
	// Should be unique for each instance of a program.
	Name       string
	Notifier   notifier.Notifier // What notifier to use.
	NextSignal time.Duration     // Notify after reaching this timeout.
	Meta       map[string]string

	// Optional callback function that will be called when notifier is called.
	CallbackFunc func(*Signal)
}

Signal represents program calling nanny to notify with given notifier if this program does not call again within NextSignal + MaxDeviation.

type Timer

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

Timer encapsulates a signal and its timer

func (*Timer) MarshalJSON

func (nt *Timer) MarshalJSON() ([]byte, error)

MarshalJSON marshals a nanny.Timer into JSON. Fields name, notifier, next_signal and meta are exported

func (*Timer) Reset

func (nt *Timer) Reset(vs validSignal)

Reset updates the nannyTimers signal to reset the timer

Jump to

Keyboard shortcuts

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