worker

package
v0.0.0-...-acd7349 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2013 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDead = errors.New("worker runner is not running")
View Source
var ErrTerminateAgent = errors.New("agent should be terminated")
View Source
var RestartDelay = 3 * time.Second

RestartDelay holds the length of time that a worker will wait between exiting and restarting.

Functions

func Stop

func Stop(worker Worker) error

Stop kills the given worker and waits for it to exit.

func WaitForEnviron

func WaitForEnviron(w *state.EnvironConfigWatcher, dying <-chan struct{}) (environs.Environ, error)

WaitForEnviron waits for an valid environment to arrive from the given watcher. It terminates with tomb.ErrDying if it receives a value on dying.

Types

type NotifyWorker

type NotifyWorker interface {
	// Wait for the NotifyWorker to finish what it is doing an exit
	Wait() error

	// Kill the running worker, indicating that it should stop what it is
	// doing and exit. Killing a running worker should return error = nil
	// from Wait.
	Kill()

	// Stop will call both Kill and then Wait for the worker to exit.
	Stop() error
}

NotifyWorker encapsulates the logic for a worker which is based on a NotifyWatcher. We do a bit of setup, and then spin waiting for the watcher to trigger or for us to be killed, and then teardown cleanly.

func NewNotifyWorker

func NewNotifyWorker(handler WatchHandler) NotifyWorker

NewNotifyWorker starts a new worker running the business logic from the handler. The worker loop is started in another goroutine as a side effect of calling this.

type Runner

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

Runner runs a set of workers, restarting them as necessary when they fail.

func NewRunner

func NewRunner(isFatal func(error) bool, moreImportant func(err0, err1 error) bool) *Runner

NewRunner creates a new Runner. When a worker finishes, if its error is deemed fatal (determined by calling isFatal), all the other workers will be stopped and the runner itself will finish. Of all the fatal errors returned by the stopped workers, only the most important one, determined by calling moreImportant, will be returned from Runner.Wait. Non-fatal errors will not be returned.

The function isFatal(err) returns whether err is a fatal error. The function moreImportant(err0, err1) returns whether err0 is considered more important than err1.

func (*Runner) Kill

func (runner *Runner) Kill()

func (*Runner) StartWorker

func (runner *Runner) StartWorker(id string, startFunc func() (Worker, error)) error

StartWorker starts a worker running associated with the given id. The startFunc function will be called to create the worker; when the worker exits, it will be restarted as long as it does not return a fatal error.

If there is already a worker with the given id, nothing will be done.

StartWorker returns ErrDead if the runner is not running.

func (*Runner) StopWorker

func (runner *Runner) StopWorker(id string) error

StopWorker stops the worker associated with the given id. It does nothing if there is no such worker.

StopWorker returns ErrDead if the runner is not running.

func (*Runner) Wait

func (runner *Runner) Wait() error

type WatchHandler

type WatchHandler interface {

	// SetUp starts the handler, this should create the watcher we will be
	// waiting on for more events. SetUp can return a Watcher even if there
	// is an error, and NotifyWorker will make sure to stop the Watcher.
	SetUp() (api.NotifyWatcher, error)

	// TearDown should cleanup any resources that are left around
	TearDown() error

	// Handle is called when the Watcher has indicated there are changes,
	// do whatever work is necessary to process it
	Handle() error

	// String is used when reporting. It is required because NotifyWatcher
	// is wrapping the WatchHandler, but the WatchHandler is the
	// interesting (identifying) logic.
	String() string
}

WatchHandler implements the business logic that is triggered as part of watching a NotifyWatcher.

type Worker

type Worker interface {
	// Kill asks the worker to stop without necessarily
	// waiting for it to do so.
	Kill()
	// Wait waits for the worker to exit and returns any
	// error encountered when it was running.
	Wait() error
}

Worker is implemented by a running worker.

Directories

Path Synopsis
hook
hook provides types that define the hooks known to the Uniter
hook provides types that define the hooks known to the Uniter
jujuc
The worker/uniter/jujuc package implements the server side of the jujuc proxy tool, which forwards command invocations to the unit agent process so that they can be executed against specific state.
The worker/uniter/jujuc package implements the server side of the jujuc proxy tool, which forwards command invocations to the unit agent process so that they can be executed against specific state.
relation
relation implements persistent local storage of a unit's relation state, and translation of relation changes into hooks that need to be run.
relation implements persistent local storage of a unit's relation state, and translation of relation changes into hooks that need to be run.

Jump to

Keyboard shortcuts

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