trigger

package
v0.0.0-...-2af547a Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2020 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package trigger provides tools for remotely controlling service lifecycle

Index

Constants

This section is empty.

Variables

View Source
var ErrRateLimitExceeded = errors.New("Rate limit exceeded for trigger")

ErrRateLimitExceeded indicates that the trigger has been called more than the allowed number of times within the specified duration, and so the guarded trigger will not be called.

Functions

func LoadPlugin

func LoadPlugin()

LoadPlugin being called forces the package to be loaded in order to ensure that the resource types are registered during the package's Init.

Types

type CompoundTrigger

type CompoundTrigger struct {
	Triggers []Triggerrer
}

CompoundTrigger is a Triggerrer that allows more than one trigger to be fired off at a time. It any trigger returns an error, it isn't guaranteed that all triggers will fire.

func (*CompoundTrigger) Trigger

func (c *CompoundTrigger) Trigger() error

Trigger executes all the child triggers, exiting immediately after a single failure.

func (*CompoundTrigger) UnmarshalJSON

func (c *CompoundTrigger) UnmarshalJSON(input []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler.

type DelayTrigger

type DelayTrigger struct {
	DelayedTrigger Triggerrer
	Delay          time.Duration
	// contains filtered or unexported fields
}

DelayTrigger is a Triggerrer that delays the execution of another trigger for at least a minimum amount of time after the most recent request. The obvious analogy would be a screen saver, which will start after a certain period has elapsed, but the timer is reset quite often.

func NewDelayTrigger

func NewDelayTrigger(
	delayedTrigger Triggerrer,
	delay time.Duration,
) *DelayTrigger

NewDelayTrigger initializes a DelayTrigger. It might not be strictly necessary anymore.

func (*DelayTrigger) Trigger

func (d *DelayTrigger) Trigger() error

Trigger sets or resets the delay after which it will execute the child trigger. The child trigger will be executed no sooner than the delay time after any particular call, but subsequent calls may extend that time out further (possibly indefinitely).

func (*DelayTrigger) UnmarshalJSON

func (d *DelayTrigger) UnmarshalJSON(input []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler.

type RateLimitTrigger

type RateLimitTrigger struct {
	GuardedTrigger Triggerrer
	MaxAllowed     uint
	Period         time.Duration
	// contains filtered or unexported fields
}

RateLimitTrigger is a Triggerrer that will prevent a guarded trigger from being called more than a specified number of times over a specified duration.

func NewRateLimitTrigger

func NewRateLimitTrigger(
	guardedTrigger Triggerrer,
	maxAllowed uint,
	period time.Duration,
) *RateLimitTrigger

NewRateLimitTrigger initializes a RateLimitTrigger. It may no longer be strictly necessary.

func (*RateLimitTrigger) Trigger

func (r *RateLimitTrigger) Trigger() error

Trigger executes its guarded trigger if and only if it has not be called more than the allowed number of times within the specified rolling window of time. If the rate limit is exceeded, ErrRateLimitExceeded will be returned, and the guarded trigger will not be called.

func (*RateLimitTrigger) UnmarshalJSON

func (r *RateLimitTrigger) UnmarshalJSON(input []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler.

type ShellTriggerrer

type ShellTriggerrer struct {
	Command string
	Args    []string
}

ShellTriggerrer is a basic Triggerrer that calls a stored shell command (along with arguments) when triggered.

The message given to TriggerString will be passed to the command via stdin.

func NewShellTriggerrer

func NewShellTriggerrer(
	command string,
	args []string,
) *ShellTriggerrer

NewShellTriggerrer constructs a new ShellTriggerrer given the command (and arguments) to be run each time TriggerString is called. Entire shell scripts could potentially be stored in the arguments, though the trigger could just as easily call an external shell script. As a result, a wide variety of actions could be taken based on the message passed in via stdin.

func (*ShellTriggerrer) Trigger

func (s *ShellTriggerrer) Trigger() (err error)

Trigger will execute the given command with the given args using the system shell.

func (*ShellTriggerrer) UnmarshalJSON

func (s *ShellTriggerrer) UnmarshalJSON(input []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler.

type SqsTriggerrer

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

SqsTriggerrer is a work-in-progress that is intended to eventually send SQS messages as the result of a triggering event.

func NewSqsTriggerrer

func NewSqsTriggerrer(url string) *SqsTriggerrer

NewSqsTriggerrer initializes a SqsTriggerrer. It may no longer be strictly necessary.

func (*SqsTriggerrer) Trigger

func (handler *SqsTriggerrer) Trigger(message string) (err error)

Trigger implemented Triggerrer and actually performs the encapsulated behavior.

type Triggerrer

type Triggerrer interface {
	Trigger() (err error)
}

Triggerrer is an abstract interface describing a system which provides triggers that can be called based on certain events (like a service being detected as down, an amount of time passing without a service being accessed, etc.).

Jump to

Keyboard shortcuts

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