singular

package
v0.0.0-...-a0d7459 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2017 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrRefresh = errors.New("model responsibility unclear, please retry")

ErrRefresh indicates that the flag's Check result is no longer valid, and a new FlagWorker must be started to get a valid result.

View Source
var PingInterval = 10 * time.Second

Functions

func Manifold

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold returns a dependency.Manifold that will run a FlagWorker and expose it to clients as a engine.Flag resource.

func New

func New(underlying jworker.Runner, conn Conn) (jworker.Runner, error)

New returns a Runner that can be used to start workers that will only run a single instance. The conn value is used to determine whether to run the workers or not.

If conn.IsMaster returns true, any workers started will be started on the underlying runner.

If conn.IsMaster returns false, any workers started will actually start do-nothing placeholder workers on the underlying runner that continually ping the connection until a ping fails and then exit with that error.

func NewWorker

func NewWorker(config FlagConfig) (worker.Worker, error)

NewWorker calls NewFlagWorker but returns a more convenient type. It's a suitable default value for ManifoldConfig.NewWorker.

Types

type Conn

type Conn interface {
	// IsMaster reports whether this connection is currently held by
	// the (singular) master of the resource.
	IsMaster() (bool, error)

	// Ping probes the resource and returns an error if the the
	// connection has failed. If the master changes, this method
	// must return an error.
	Ping() error
}

Conn represents a connection to some resource.

type Facade

type Facade interface {
	Claim(duration time.Duration) error
	Wait() error
}

Facade exposes the capabilities required by a FlagWorker.

func NewFacade

func NewFacade(apiCaller base.APICaller, controllerTag names.MachineTag) (Facade, error)

NewFacade creates a Facade from an APICaller and a controller. It's a suitable default value for ManifoldConfig.NewFacade.

type FlagConfig

type FlagConfig struct {
	Clock    clock.Clock
	Facade   Facade
	Duration time.Duration
}

FlagConfig holds a FlagWorker's dependencies and resources.

func (FlagConfig) Validate

func (config FlagConfig) Validate() error

Validate returns an error if the config cannot be expected to run a FlagWorker.

type FlagWorker

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

FlagWorker implements worker.Worker and util.Flag, representing controller ownership of a model, such that the Flag's validity is tied to the Worker's lifetime.

func NewFlagWorker

func NewFlagWorker(config FlagConfig) (*FlagWorker, error)

func (*FlagWorker) Check

func (flag *FlagWorker) Check() bool

Check is part of the util.Flag interface.

Check returns true if the flag indicates that the configured Identity (i.e. this controller) has taken control of the configured Scope (i.e. the model we want to manage exclusively).

The validity of this result is tied to the lifetime of the FlagWorker; once the worker has stopped, no inferences may be drawn from any Check result.

func (*FlagWorker) Kill

func (flag *FlagWorker) Kill()

Kill is part of the worker.Worker interface.

func (*FlagWorker) Wait

func (flag *FlagWorker) Wait() error

Wait is part of the worker.Worker interface.

type ManifoldConfig

type ManifoldConfig struct {
	ClockName     string
	APICallerName string
	AgentName     string
	Duration      time.Duration

	NewFacade func(base.APICaller, names.MachineTag) (Facade, error)
	NewWorker func(FlagConfig) (worker.Worker, error)
}

ManifoldConfig holds the information necessary to run a FlagWorker in a dependency.Engine.

Jump to

Keyboard shortcuts

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