leadership

package
v0.0.0-...-b9bb202 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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.

Functions

func Manifold

func Manifold(config ManifoldConfig) dependency.Manifold

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

Types

type ManifoldConfig

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

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

func NewTracker

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

func (t *Tracker) ApplicationName() string

ApplicationName is part of the leadership.Tracker interface.

func (*Tracker) ClaimDuration

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

ClaimDuration is part of the leadership.Tracker interface.

func (*Tracker) ClaimLeader

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

ClaimLeader is part of the leadership.Tracker interface.

func (*Tracker) Kill

func (t *Tracker) Kill()

Kill is part of the worker.Worker interface.

func (*Tracker) Wait

func (t *Tracker) Wait() error

Wait is part of the worker.Worker interface.

func (*Tracker) WaitLeader

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

WaitLeader is part of the leadership.Tracker interface.

func (*Tracker) WaitMinion

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

WaitMinion is part of the leadership.Tracker interface.

Jump to

Keyboard shortcuts

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