elector

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package elector elects one leader per cluster with a lease row.

Index

Constants

View Source
const (
	DefaultName           = "default"
	DefaultTTL            = 15 * time.Second
	DefaultReleaseTimeout = 5 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name           string
	ClientID       string
	TTL            time.Duration
	Store          job.LeaseStore
	Clock          clock.Clock
	Services       func(ctx context.Context)
	OnChange       func(leader bool)
	Logger         *slog.Logger
	ReleaseTimeout time.Duration
}

type Elector

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

Elector holds a lease to elect one leader and runs the leader services while it holds it.

func New

func New(cfg Config) (*Elector, error)

New validates cfg and applies defaults.

func (*Elector) Crash

func (e *Elector) Crash()

Crash stops the leader services and drops the lease without releasing it.

func (*Elector) Interval

func (e *Elector) Interval() time.Duration

func (*Elector) IsLeader

func (e *Elector) IsLeader() bool

func (*Elector) Run

func (e *Elector) Run(ctx context.Context) error

Run competes for the lease until ctx is cancelled, then releases it.

func (*Elector) Wake

func (e *Elector) Wake()

Jump to

Keyboard shortcuts

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