controller

package
v0.0.4-solo Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2018 License: Apache-2.0 Imports: 9 Imported by: 25

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSync added in v0.1.13

func DefaultSync(ctx context.Context, store entitystore.EntityStore, entityType reflect.Type, resyncPeriod time.Duration, filter entitystore.Filter) ([]entitystore.Entity, error)

DefaultSync simply returns a list of entities in non-READY state which have been modified since the resync period.

Types

type Controller

type Controller interface {
	Start()
	Shutdown()

	Watcher() Watcher

	AddEntityHandler(h EntityHandler)
}

Controller defines an interface for a generic controller

func NewController

func NewController(options Options) Controller

NewController creates a new controller

type DefaultController

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

DefaultController defines a struct for a generic controller

func (*DefaultController) AddEntityHandler

func (dc *DefaultController) AddEntityHandler(h EntityHandler)

AddEntityHandler adds entity handlers

func (*DefaultController) Shutdown

func (dc *DefaultController) Shutdown()

Shutdown stops the controller loop

func (*DefaultController) Start

func (dc *DefaultController) Start()

Start starts the controller watch loop

func (*DefaultController) Watcher

func (dc *DefaultController) Watcher() Watcher

Watcher returns a watcher channel for the controller

type EntityHandler

type EntityHandler interface {
	Type() reflect.Type
	Add(ctx context.Context, obj entitystore.Entity) error
	Update(ctx context.Context, obj entitystore.Entity) error
	Delete(ctx context.Context, obj entitystore.Entity) error
	Error(ctx context.Context, obj entitystore.Entity) error
	// Sync returns a list of entities which to process.  This method should call out and determine the actual state
	// of entities.
	Sync(ctx context.Context, resyncPeriod time.Duration) ([]entitystore.Entity, error)
}

EntityHandler define an interface for entity operations of a generic controller

type Options

type Options struct {
	ServiceName string

	ResyncPeriod time.Duration
	Workers      int
}

Options defines controller configuration

type WatchEvent added in v0.1.15

type WatchEvent struct {
	Entity entitystore.Entity
	Ctx    context.Context
}

WatchEvent captures entity together with the associated context

type Watcher

type Watcher chan<- WatchEvent

Watcher channel type

func (*Watcher) OnAction

func (w *Watcher) OnAction(ctx context.Context, e entitystore.Entity)

OnAction pushes an entity onto the watcher channel

Jump to

Keyboard shortcuts

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