policy

package
v0.0.0-...-bb3eb04 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidCondition is returned if a condition is supplied that doesn't meet the requirements of the method.
	// For example, providing a condition without a cron field to the addCronEntry rule would yield this error.
	ErrInvalidCondition = errors.New("invalid condition supplied")
	// ErrInvalidAction is returned if an action is supplied that doesn't meet the requirements of the method.
	// For example, providing a timer action with an empty body would yield this error.
	ErrInvalidAction = errors.New("invalid action supplied")
)

Functions

This section is empty.

Types

type Engine

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

Engine contains a single instance of a policy engine. This engine contains one or more policies, subscribes to updates from one or more services to trigger conditional changes, and uses these subscribed services to execute one or more actions when the relevant policy executes.

func NewEngine

func NewEngine(logger *zap.Logger, state *State) *Engine

NewEngine creates a new policy engine.

func (*Engine) AddPolicy

func (e *Engine) AddPolicy(policy *Policy)

AddPolicy registers a new policy with the policy engine. Policies are held in an ordered list, descending by their weights, and this add will ensure the inserted policy is placed in the appropriate location.

func (*Engine) Done

func (e *Engine) Done() <-chan bool

Done allows observers to watch for when the policy execution has completed.

func (*Engine) Refresh

func (e *Engine) Refresh() chan<- bool

Refresh returns a channel that can be written to to trigger a new policy execution.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context)

Run begins the policy evaluation process. The evaluation can be terminated by aborting the supplied context.

type State

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

State represents the current state of the system this policy engine is monitoring. The engine will subscribe to updates from this state, and will execute operations against this state to change the state of the system.

func NewState

func NewState(logger *zap.Logger, conn *grpc.ClientConn) *State

NewState creates a new state entity to manage.

func (*State) Monitor

func (s *State) Monitor(ctx context.Context)

Monitor is used to track changes to devices

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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