trigger

package
v1.6.0-rc4 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package trigger provides a mechanism to trigger actions that require to be serialized while providing a non-blocking notification mechanism

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MetricsObserver added in v1.6.0

type MetricsObserver interface {
	// PostRun is called after a trigger run with the call duration, the
	// latency between 1st queue request and the call run and the number of
	// queued events folded into the last run
	PostRun(callDuration, latency time.Duration, folds int)

	// QueueEvent is called when Trigger() is called to schedule a trigger
	// run
	QueueEvent(reason string)
}

MetricsObserver is the interface a metrics collector has to implement in order to collect trigger metrics

type Parameters

type Parameters struct {
	// MinInterval is the minimum required interval between invocations of
	// TriggerFunc
	MinInterval time.Duration

	// TriggerFunc is the function to be called when Trigger() is called
	// while respecting MinInterval and serialization
	TriggerFunc func(reasons []string)

	MetricsObserver MetricsObserver

	// Name is the unique name of the trigger. It must be provided in a
	// format compatible to be used as prometheus name string.
	Name string
	// contains filtered or unexported fields
}

Parameters are the user specified parameters

type Trigger

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

Trigger represents an active trigger logic. Use NewTrigger() to create a trigger

func NewTrigger

func NewTrigger(p Parameters) (*Trigger, error)

NewTrigger returns a new trigger based on the provided parameters

func (*Trigger) Shutdown

func (t *Trigger) Shutdown()

Shutdown stops the trigger mechanism

func (*Trigger) Trigger

func (t *Trigger) Trigger()

Trigger triggers the call to TriggerFunc as specified in the parameters provided to NewTrigger(). It respects MinInterval and ensures that calls to TriggerFunc are serialized. This function is non-blocking and will return immediately before TriggerFunc is potentially triggered and has completed.

func (*Trigger) TriggerWithReason

func (t *Trigger) TriggerWithReason(reason string)

Trigger triggers the call to TriggerFunc as specified in the parameters provided to NewTrigger(). It respects MinInterval and ensures that calls to TriggerFunc are serialized. This function is non-blocking and will return immediately before TriggerFunc is potentially triggered and has completed.

Jump to

Keyboard shortcuts

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