worker

package
v0.0.0-...-a002913 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2015 License: AGPL-3.0 Imports: 10 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 ErrKilled = errors.New("worker killed")

ErrKilled can be returned by the PeriodicWorkerCall to signify that the function has returned as a result of a Stop() or Kill() signal and that the function was able to stop cleanly

View Source
var ErrRebootMachine = errors.New("machine needs to reboot")
View Source
var ErrShutdownMachine = errors.New("machine needs to shutdown")
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 apiwatcher.NotifyWatcher, st EnvironConfigGetter, 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 EnvironConfigGetter

type EnvironConfigGetter interface {
	EnvironConfig() (*config.Config, error)
}

EnvironConfigGetter interface defines a way to read the environment configuration.

type EnvironConfigObserver

type EnvironConfigObserver interface {
	EnvironConfigGetter
	WatchForEnvironConfigChanges() (apiwatcher.NotifyWatcher, error)
}

EnvironConfigObserver interface defines a way to read the environment configuration and watch for changes.

type EnvironObserver

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

EnvironObserver watches the current environment configuration and makes it available. It discards invalid environment configurations.

func NewEnvironObserver

func NewEnvironObserver(st EnvironConfigObserver) (*EnvironObserver, error)

NewEnvironObserver waits for the environment to have a valid environment configuration and returns a new environment observer. While waiting for the first environment configuration, it will return with tomb.ErrDying if it receives a value on dying.

func (*EnvironObserver) Environ

func (obs *EnvironObserver) Environ() environs.Environ

Environ returns the most recent valid Environ.

func (*EnvironObserver) Kill

func (obs *EnvironObserver) Kill()

func (*EnvironObserver) Wait

func (obs *EnvironObserver) Wait() error

type FinishedWorker

type FinishedWorker struct{}

FinishedWorker is a worker that stops immediately with no error when started by a Runner, which then removes it from the list of workers without restarting it. Simply return FinishedWorker{} where you need to avoid starting a worker at all.

func (FinishedWorker) Kill

func (w FinishedWorker) Kill()

Kill implements Worker.Kill() and does nothing.

func (FinishedWorker) Wait

func (w FinishedWorker) Wait() error

Wait implements Worker.Wait() and immediately returns no error.

type NewTimerFunc

type NewTimerFunc func(time.Duration) PeriodicTimer

NewTimerFunc is a constructor used to obtain the instance of PeriodicTimer periodicWorker uses on its loop.

type NotifyWatchHandler

type NotifyWatchHandler 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 the notify Worker will make sure
	// to stop the watcher.
	SetUp() (apiWatcher.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. The done channel is closed if
	// the worker is being interrupted to finish. Any worker should avoid any
	// bare channel reads or writes, but instead use a select with the done
	// channel.
	Handle(done <-chan struct{}) error
}

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

type PeriodicTimer

type PeriodicTimer interface {
	// Reset changes the timer to expire after duration d.
	// It returns true if the timer had been active, false
	// if the timer had expired or been stopped.
	Reset(time.Duration) bool
	// CountDown returns the channel used to signal expiration of
	// the timer duration. The channel is called C in the base
	// implementation of timer but the name is confusing.
	CountDown() <-chan time.Time
}

PeriodicTimer is an interface for the timer that periodicworker will use to handle the calls.

func NewTimer

func NewTimer(d time.Duration) PeriodicTimer

NewTimer is the default implementation of NewTimerFunc.

type PeriodicWorkerCall

type PeriodicWorkerCall func(stop <-chan struct{}) error

PeriodicWorkerCall represents the callable to be passed to the periodic worker to be run every elapsed period.

type Runner

type Runner interface {
	Worker
	StartWorker(id string, startFunc func() (Worker, error)) error
	StopWorker(id string) error
}

Runner is implemented by instances capable of starting and stopping workers.

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.

type StringsWatchHandler

type StringsWatchHandler 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 strings Worker will make sure to
	// stop the watcher.
	SetUp() (apiWatcher.StringsWatcher, 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(changes []string) error
}

StringsWatchHandler implements the business logic triggered as part of watching a StringsWatcher.

type Timer

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

Timer implements PeriodicTimer.

func (*Timer) CountDown

func (t *Timer) CountDown() <-chan time.Time

CountDown implements PeriodicTimer.

func (*Timer) Reset

func (t *Timer) Reset(d time.Duration) bool

Reset implements PeriodicTimer.

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.

func NewNoOpWorker

func NewNoOpWorker() Worker

func NewNotifyWorker

func NewNotifyWorker(handler NotifyWatchHandler) Worker

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.

func NewPeriodicWorker

func NewPeriodicWorker(call PeriodicWorkerCall, period time.Duration, timerFunc NewTimerFunc) Worker

NewPeriodicWorker returns a worker that runs the given function continually sleeping for sleepDuration in between each call, until Kill() is called The stopCh argument will be closed when the worker is killed. The error returned by the doWork function will be returned by the worker's Wait function.

func NewSimpleWorker

func NewSimpleWorker(doWork func(stopCh <-chan struct{}) error) Worker

NewSimpleWorker returns a worker that runs the given function. The stopCh argument will be closed when the worker is killed. The error returned by the doWork function will be returned by the worker's Wait function.

func NewStringsWorker

func NewStringsWorker(handler StringsWatchHandler) Worker

NewStringsWorker 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.

Directories

Path Synopsis
Package charmdir provides the manifold that coordinates the availability of a charm directory among workers.
Package charmdir provides the manifold that coordinates the availability of a charm directory among workers.
The dependency package exists to address a general problem with shared resources and the management of their lifetimes.
The dependency package exists to address a general problem with shared resources and the management of their lifetimes.
Package diskmanager defines a worker that periodically lists block devices on the machine it runs on.
Package diskmanager defines a worker that periodically lists block devices on the machine it runs on.
package gate provides a mechanism by which independent workers can wait for one another to finish a task, without introducing explicit dependencies between those workers.
package gate provides a mechanism by which independent workers can wait for one another to finish a task, without introducing explicit dependencies between those workers.
metrics
collect
Package collect provides a worker that executes the collect-metrics hook periodically, as long as the workload has been started (between start and stop hooks).
Package collect provides a worker that executes the collect-metrics hook periodically, as long as the workload has been started (between start and stop hooks).
sender
Package sender contains the implementation of the metric sender manifold.
Package sender contains the implementation of the metric sender manifold.
spool
Package spool contains the implementation of a worker that extracts the spool directory path from the agent config and enables other workers to write and read metrics to and from a the spool directory using a writer and a reader.
Package spool contains the implementation of a worker that extracts the spool directory path from the agent config and enables other workers to write and read metrics to and from a the spool directory using a writer and a reader.
Package storageprovisioner provides a worker that manages the provisioning and deprovisioning of storage volumes and filesystems, and attaching them to and detaching them from machines.
Package storageprovisioner provides a worker that manages the provisioning and deprovisioning of storage volumes and filesystems, and attaching them to and detaching them from machines.
hook
hook provides types that define the hooks known to the Uniter
hook provides types that define the hooks known to the Uniter
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.
runner/context
Package context contains the ContextFactory and Context definitions.
Package context contains the ContextFactory and Context definitions.
runner/jujuc
The worker/uniter/runner/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/runner/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.
storage
Package storage contains the storage subsystem for the uniter, responding to changes in storage attachments (lifecycle, volume/filesystem details) by queuing hooks and managing the storage attachments' lifecycle.
Package storage contains the storage subsystem for the uniter, responding to changes in storage attachments (lifecycle, volume/filesystem details) by queuing hooks and managing the storage attachments' lifecycle.

Jump to

Keyboard shortcuts

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