juju: github.com/wallyworld/juju/worker/leadership Index | Files

package leadership

import "github.com/wallyworld/juju/worker/leadership"


Package Files

manifold.go tracker.go


var NewManifoldWorker = func(agent agent.Agent, apiCaller base.APICaller, clock clock.Clock, guarantee time.Duration) (worker.Worker, error) {
    tag := agent.CurrentConfig().Tag()
    unitTag, ok := tag.(names.UnitTag)
    if !ok {
        return nil, fmt.Errorf("expected a unit tag; got %q", tag)
    claimer := leadership.NewClient(apiCaller)
    return NewTracker(unitTag, claimer, clock, guarantee), nil

NewManifoldWorker wraps NewTracker for the convenience of startFunc. It exists primarily to be patched out via NewManifoldWorker for ease of testing, and is not itself directly tested. It would almost certainly be better to pass the constructor dependencies in as explicit manifold config.

func Manifold Uses

func Manifold(config ManifoldConfig) dependency.Manifold

Manifold returns a manifold whose worker wraps a Tracker working on behalf of the dependency identified by AgentName.

type ManifoldConfig Uses

type ManifoldConfig struct {
    AgentName           string
    APICallerName       string
    Clock               clock.Clock
    LeadershipGuarantee time.Duration

ManifoldConfig defines the names of the manifolds on which a Manifold will depend.

type Tracker Uses

type Tracker struct {
    // contains filtered or unexported fields

func NewTracker Uses

func NewTracker(tag names.UnitTag, claimer leadership.Claimer, clock clock.Clock, duration time.Duration) *Tracker

NewTracker returns a *Tracker that attempts to claim and retain application leadership for the supplied unit. It will claim leadership for twice the supplied duration, and once it's leader it will renew leadership every time the duration elapses. Thus, successful leadership claims on the resulting Tracker will guarantee leadership for the duration supplied here without generating additional calls to the supplied manager (which may very well be on the other side of a network connection).

func (*Tracker) ApplicationName Uses

func (t *Tracker) ApplicationName() string

ApplicationName is part of the leadership.Tracker interface.

func (*Tracker) ClaimDuration Uses

func (t *Tracker) ClaimDuration() time.Duration

ClaimDuration is part of the leadership.Tracker interface.

func (*Tracker) ClaimLeader Uses

func (t *Tracker) ClaimLeader() leadership.Ticket

ClaimLeader is part of the leadership.Tracker interface.

func (*Tracker) Kill Uses

func (t *Tracker) Kill()

Kill is part of the worker.Worker interface.

func (*Tracker) Wait Uses

func (t *Tracker) Wait() error

Wait is part of the worker.Worker interface.

func (*Tracker) WaitLeader Uses

func (t *Tracker) WaitLeader() leadership.Ticket

WaitLeader is part of the leadership.Tracker interface.

func (*Tracker) WaitMinion Uses

func (t *Tracker) WaitMinion() leadership.Ticket

WaitMinion is part of the leadership.Tracker interface.

Package leadership imports 13 packages (graph). Updated 2020-08-06. Refresh now. Tools for package owners.