juju-core: launchpad.net/juju-core/worker Index | Files | Directories

package worker

import "launchpad.net/juju-core/worker"

Index

Package Files

errors.go finishedworker.go noopworker.go periodicworker.go runner.go simpleworker.go

Constants

const RestartDelay = 3 * time.Second

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

Variables

var (
    ErrTerminateAgent  = errors.New("agent should be terminated")
    ErrRebootMachine   = errors.New("machine needs to reboot")
    ErrShutdownMachine = errors.New("machine needs to shutdown")
)

These errors are returned by various specific workers in the hope that they will have some specific effect on the top-level agent running that worker.

It should be clear that they don't belong here, and certainly shouldn't be used as they are today: e.g. a uniter has *no fricking idea* whether its host agent should shut down. A uniter can return ErrUnitDead, and its host might need to respond to that, perhaps by returning an error specific to *its* host; depending on these values punching right through N layers (but only when we want them to!) is kinda terrible.

var ErrDead = errors.New("worker runner is not running")
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

func Stop Uses

func Stop(worker Worker) error

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

type FinishedWorker Uses

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 Uses

func (w FinishedWorker) Kill()

Kill implements Worker.Kill() and does nothing.

func (FinishedWorker) Wait Uses

func (w FinishedWorker) Wait() error

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

type NewTimerFunc Uses

type NewTimerFunc func(time.Duration) PeriodicTimer

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

type PeriodicTimer Uses

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 Uses

func NewTimer(d time.Duration) PeriodicTimer

NewTimer is the default implementation of NewTimerFunc.

type PeriodicWorkerCall Uses

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 Uses

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 Uses

func NewRunner(isFatal func(error) bool, moreImportant func(err0, err1 error) bool, restartDelay time.Duration) 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 Timer Uses

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

Timer implements PeriodicTimer.

func (*Timer) CountDown Uses

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

CountDown implements PeriodicTimer.

func (*Timer) Reset Uses

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

Reset implements PeriodicTimer.

type Worker Uses

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 Uses

func NewNoOpWorker() Worker

func NewPeriodicWorker Uses

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 Uses

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.

type Workers Uses

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

Workers is an order-preserving registry of worker factory functions.

func NewWorkers Uses

func NewWorkers() Workers

NewWorkers returns a new Workers.

func (*Workers) Add Uses

func (r *Workers) Add(id string, newWorker func() (Worker, error)) error

Add registered the factory function for the identified worker.

func (Workers) IDs Uses

func (r Workers) IDs() []string

IDs returns the list of registered worker IDs.

func (*Workers) Start Uses

func (r *Workers) Start(runner Runner) error

Start starts all the registered workers under the given runner.

Directories

PathSynopsis
apiaddressupdater
authenticationworker
cleaner
deployer
firewaller
instancepoller
logger
machiner
minunitsworker
peergrouper
provisioner
resumer
singular
terminationworker
uniter
uniter/charm
uniter/hookhook provides types that define the hooks known to the Uniter
uniter/relationrelation implements persistent local storage of a unit's relation state, and translation of relation changes into hooks that need to be run.
upgrader

Package worker imports 5 packages (graph) and is imported by 45 packages. Updated 2016-07-18. Refresh now. Tools for package owners.