lifeflag

package
v0.0.0-...-23dbee4 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrNotFound indicates that the worker cannot run because
	// the configured entity does not exist.
	ErrNotFound = apilifeflag.ErrEntityNotFound

	// ErrValueChanged indicates that the result of Check is
	// outdated, and the worker should be restarted.
	ErrValueChanged = errors.ConstError("flag value changed")
)

Variables

This section is empty.

Functions

func Manifold

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold returns a dependency.Manifold that will run a Worker as configured.

func NewWorker

func NewWorker(ctx context.Context, config Config) (worker.Worker, error)

Types

type Config

type Config struct {
	Facade         Facade
	Entity         names.Tag
	Result         life.Predicate
	NotFoundIsDead bool
}

Config holds the configuration and dependencies for a worker.

func (Config) Validate

func (config Config) Validate() error

Validate returns an error if the config cannot be expected to drive a functional worker.

type Facade

type Facade interface {
	Watch(context.Context, names.Tag) (watcher.NotifyWatcher, error)
	Life(context.Context, names.Tag) (life.Value, error)
}

Facade exposes capabilities required by the worker.

type ManifoldConfig

type ManifoldConfig struct {
	APICallerName string
	AgentName     string

	Entity         names.Tag
	Result         life.Predicate
	Filter         dependency.FilterFunc
	NotFoundIsDead bool

	NewFacade func(base.APICaller) (Facade, error)
	NewWorker func(context.Context, Config) (worker.Worker, error)
}

ManifoldConfig describes how to configure and construct a Worker, and what registered resources it may depend upon.

type Worker

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

Worker holds the result of some predicate regarding an entity's life, and fails with ErrValueChanged when the result of the predicate changes.

func New

func New(ctx context.Context, config Config) (*Worker, error)

New returns a worker that exposes the result of the configured predicate when applied to the configured entity's life value, and fails with ErrValueChanged when the result changes.

func (*Worker) Check

func (w *Worker) Check() bool

Check is part of the util.Flag interface.

func (*Worker) Kill

func (w *Worker) Kill()

Kill is part of the worker.Worker interface.

func (*Worker) Wait

func (w *Worker) Wait() error

Wait is part of the worker.Worker interface.

Jump to

Keyboard shortcuts

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