runtime

package
v0.8.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SignalTypeNamed is a named signal.
	SignalTypeNamed = iota
	// SignalTypeConstant is a constant signal.
	SignalTypeConstant
)

Variables

This section is empty.

Functions

func CircuitModule

func CircuitModule() fx.Option

CircuitModule returns fx options of Circuit for the main app.

Types

type Circuit

type Circuit struct {
	// Policy Read API
	iface.Policy
	// contains filtered or unexported fields
}

Circuit manages the runtime state of a set of components and their inter linkages via signals.

func NewCircuitAndOptions

func NewCircuitAndOptions(
	compWithPortsList []CompiledComponentAndPorts,
	policyReadAPI iface.Policy,
	registry status.Registry,
) (*Circuit, fx.Option)

NewCircuitAndOptions create a new Circuit struct along with fx options.

func (*Circuit) DynamicConfigUpdate added in v0.4.0

func (circuit *Circuit) DynamicConfigUpdate(event notifiers.Event, unmarshaller config.Unmarshaller)

DynamicConfigUpdate updates the circuit with the new dynamic config.

func (*Circuit) Execute

func (circuit *Circuit) Execute(tickInfo TickInfo) error

Execute runs one tick of computations of all the Components in the Circuit.

func (*Circuit) LockExecution

func (circuit *Circuit) LockExecution()

LockExecution locks the execution of the circuit.

func (*Circuit) RegisterTickEndCallback

func (circuit *Circuit) RegisterTickEndCallback(ec TickEndCallback)

RegisterTickEndCallback adds a callback function to be called when a tick ends.

func (*Circuit) RegisterTickStartCallback added in v0.2.1

func (circuit *Circuit) RegisterTickStartCallback(sc TickStartCallback)

RegisterTickStartCallback adds a callback function to be called when a tick starts.

func (*Circuit) UnlockExecution

func (circuit *Circuit) UnlockExecution()

UnlockExecution unlocks the execution of the circuit.

type CircuitAPI

type CircuitAPI interface {
	iface.Policy
	RegisterTickEndCallback(ec TickEndCallback)
	RegisterTickStartCallback(sc TickStartCallback)
	LockExecution()
	UnlockExecution()
}

CircuitAPI is for read only access to policy and also provides methods for acquiring & releasing circuit execution lock.

type CircuitMetrics

type CircuitMetrics struct {
	SignalSummaryVec *prometheus.SummaryVec
}

CircuitMetrics holds prometheus metrics related circuit.

type CompiledComponent

type CompiledComponent struct {
	Component     Component
	MapStruct     map[string]any
	Name          string
	ComponentType ComponentType
}

CompiledComponent consists of a Component, its MapStruct and Name.

type CompiledComponentAndPorts

type CompiledComponentAndPorts struct {
	InPortToSignalsMap  PortToSignal
	OutPortToSignalsMap PortToSignal
	CompiledComponent   CompiledComponent
}

CompiledComponentAndPorts consists of a CompiledComponent and its In and Out ports.

type Component

type Component interface {
	Execute(inPortReadings PortToValue, tickInfo TickInfo) (outPortReadings PortToValue, err error)
	DynamicConfigUpdate(event notifiers.Event, unmarshaller config.Unmarshaller)
}

Component is the interface that all components must implement.

type ComponentType

type ComponentType string

ComponentType describes the type of a component based on its connectivity in the circuit.

const (
	// ComponentTypeStandAlone is a component that does not accept or emit any signals.
	ComponentTypeStandAlone ComponentType = "StandAlone"
	// ComponentTypeSource is a component that emits output signal(s) but does not accept an input signal.
	ComponentTypeSource ComponentType = "Source"
	// ComponentTypeSink is a component that accepts input signal(s) but does not emit an output signal.
	ComponentTypeSink ComponentType = "Sink"
	// ComponentTypeSignalProcessor is a component that accepts input signal(s) and emits output signal(s).
	ComponentTypeSignalProcessor ComponentType = "SignalProcessor"
)

type PortToSignal

type PortToSignal map[string][]Signal

PortToSignal is a map from port name to a slice of Signals.

type PortToValue

type PortToValue map[string][]Reading

PortToValue is a map from port name to a slice of Readings.

func (PortToValue) ReadRepeatedValuePort

func (ptv PortToValue) ReadRepeatedValuePort(portName string) []Reading

ReadRepeatedValuePort returns the reading of all the signals at port=portName. If no signal is found, []Reading{} empty list is returned.

func (PortToValue) ReadSingleValuePort

func (ptv PortToValue) ReadSingleValuePort(portName string) Reading

ReadSingleValuePort returns the reading of the first signal at port=portName. If no signal is found, InvalidReading() is returned.

type Reading added in v0.2.1

type Reading interface {
	Value() float64
	Valid() bool
}

Reading is the interface that reading implements which wraps a float Value which can be valid or invalid.

func InvalidReading added in v0.2.1

func InvalidReading() Reading

InvalidReading creates a reading with 'value' set to math.NaN(), invalid value.

func NewReading added in v0.2.1

func NewReading(value float64) Reading

NewReading creates a reading with the given value.

type Signal

type Signal struct {
	Name       string
	Value      float64
	Looped     bool
	SignalType SignalType
}

Signal represents a logical flow of Readings in a circuit and determines the linkage between Components.

func MakeSignal added in v0.5.0

func MakeSignal(signalType SignalType, name string, value float64, looped bool) Signal

MakeSignal creates a new Signal.

type SignalType added in v0.5.0

type SignalType int

SignalType enum.

type TickEndCallback

type TickEndCallback func(tickInfo TickInfo) error

TickEndCallback is a function that is called when a tick ends.

type TickInfo

type TickInfo interface {
	Timestamp() time.Time
	NextTimestamp() time.Time
	Tick() int
	Interval() time.Duration
	Serialize() *policysyncv1.TickInfo
}

TickInfo is the interface that trackInfo implements which contains information about the current tick.

func NewTickInfo added in v0.2.1

func NewTickInfo(timestamp, nextTimestamp time.Time, tick int, interval time.Duration) TickInfo

NewTickInfo returns a Tickinfo.

type TickStartCallback added in v0.2.1

type TickStartCallback func(tickInfo TickInfo) error

TickStartCallback is a function that is called when a tick starts.

Jump to

Keyboard shortcuts

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