common

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidApp = fmt.Errorf("invalid application provided")

ErrInvalidApp is returned by triggers when a non-existent app is requested.

View Source
var ErrNoChannel = fmt.Errorf("no channel to send request")

ErrNoChannel is returned when the go routine is stopped.

Functions

This section is empty.

Types

type Action

type Action struct {
	Name TriggerName
	D    cnfg.Duration                       // how often the timer fires, sets ticker.
	Fn   func(context.Context, *ActionInput) // most actions use this for triggers.
	C    chan *ActionInput                   // if provided, D is optional.

	Hide bool // prevent logging.
	// contains filtered or unexported fields
}

Action defines a trigger/timer that can be executed.

type ActionInput added in v0.4.1

type ActionInput struct {
	Type website.EventType
	Args []string
}

ActionInput is used to send data to a trigger action.

type Config

type Config struct {
	CIC             *clientinfo.Config
	*website.Server // send trigger responses to website.
	Snapshot        *snapshot.Config
	Apps            *apps.Apps
	*logs.Logger

	Services // for running service checks.
	// contains filtered or unexported fields
}

Config is the input data shared by most triggers. Everything is mandatory.

func (*Config) Add

func (c *Config) Add(action ...*Action)

Add adds a new action to our list of "Actions to run." actions are timers or triggers, or both.

func (*Config) Exec

func (c *Config) Exec(input *ActionInput, name TriggerName) bool

Exec runs a trigger. This is abastraction method used in a bunch of places.

func (*Config) GatherTriggerInfo added in v0.5.0

func (c *Config) GatherTriggerInfo() (map[string]cnfg.Duration, map[string]cnfg.Duration)

func (*Config) Get

func (c *Config) Get(name TriggerName) *Action

Get a trigger by unique name. May return nil, and that could cause a panic. We avoid panics by using a custom type with corresponding constants as input.

func (*Config) Rand added in v0.5.1

func (c *Config) Rand() *rand.Rand

Rand returns a cryptographically-insecure random number generator.

func (*Config) ReloadApp added in v0.4.1

func (c *Config) ReloadApp(reason string)

ReloadApp reloads the application configuration.

func (*Config) Run

func (c *Config) Run(ctx context.Context)

Run converts all the tickers and triggers into []reflect.SelectCase. This allows us to run a loop with a dynamic number of channels and tickers to watch.

func (*Config) SetReloadCh added in v0.4.1

func (c *Config) SetReloadCh(sighup chan os.Signal)

SetReloadCh is used to set the reload channel for triggers. This is an exported method because the channel is not always available when triggers are initialized.

func (*Config) Stop

func (c *Config) Stop(event website.EventType)

Stop shuts down the loop/goroutine that handles all triggers and timers.

type Services added in v0.4.1

type Services interface {
	RunChecks(website.EventType)
}

Services is the input interface to do things with services via triggers.

type TriggerName

type TriggerName string

TriggerName makes sure triggers have a known name.

const TrigStop TriggerName = "Stopping all triggers and timers (reload)."

TrigStop is used to signal a stop/reload.

func (TriggerName) WithInstance added in v0.3.3

func (name TriggerName) WithInstance(instance int) TriggerName

WithInstance returns a trigger name with an instance ID.

Jump to

Keyboard shortcuts

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