leaderelection

package
v0.0.0-...-e2755d2 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidOnStartedLeadingCallback is thrown if OnStartedLeading callback is not defined
	ErrInvalidOnStartedLeadingCallback = fmt.Errorf("OnStartedLeading callback must not be nil")

	// ErrInvalidOnStoppedLeadingCallback is thrown if OnStoppedLeading callback is not defined
	ErrInvalidOnStoppedLeadingCallback = fmt.Errorf("OnStoppedLeading callback must not be nil")

	// ErrInvalidLockPath is thrown if lock path for lease is not defined
	ErrInvalidLockPath = fmt.Errorf("lock path must not be nil")
)

Errors raised by package

Functions

This section is empty.

Types

type Candidate

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

Candidate is a leader election candidate.

func New

func New(id string, sessionID string, c Config, registry registry.IRegistry) (*Candidate, error)

New creates a instance of LeaderElector from a LeaderElection Config

func (*Candidate) IsLeader

func (c *Candidate) IsLeader() bool

IsLeader returns true if the last observed leader was this client else returns false.

func (*Candidate) Run

func (c *Candidate) Run(ctx context.Context) error

Run starts the leader election loop. Run will not return before leader election loop is stopped by ctx or it has stopped holding the leader lease

type Config

type Config struct {
	// LockPath is key in registry that will be used for locking
	LockPath string

	// Callbacks are callbacks that are triggered during certain lifecycle
	// events of the LeaderElector
	Callbacks LeaderCallbacks
}

Config for leaderelector

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the config

type LeaderCallbacks

type LeaderCallbacks struct {
	// OnStartedLeading is called when a LeaderElector client starts leading
	OnStartedLeading func(context.Context) error
	// OnStoppedLeading is called when a LeaderElector client stops leading
	OnStoppedLeading func(ctx context.Context)
}

LeaderCallbacks are callbacks that are triggered during certain lifecycle events of the LeaderElector. These are invoked asynchronously.

Jump to

Keyboard shortcuts

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