Documentation
¶
Index ¶
- func Provide(i *do.Injector)
- type Candidate
- type ClaimHandler
- type ElectionStore
- func (s *ElectionStore) Create(item *StoredElection) storage.PutOp[*StoredElection]
- func (s *ElectionStore) Delete(item *StoredElection) storage.DeleteValueOp[*StoredElection]
- func (s *ElectionStore) GetByKey(name Name) storage.GetOp[*StoredElection]
- func (s *ElectionStore) Key(name Name) string
- func (s *ElectionStore) Update(item *StoredElection) storage.PutOp[*StoredElection]
- func (s *ElectionStore) Watch(name Name) storage.WatchOp[*StoredElection]
- type Name
- type Service
- type StoredElection
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Candidate ¶
type Candidate struct {
// contains filtered or unexported fields
}
Candidate participates in a single named election. Once elected, candidate maintains leadership until its Stop method is called or until it fails to renew its leadership claim.
func NewCandidate ¶
func NewCandidate( store *ElectionStore, loggerFactory *logging.Factory, electionName Name, candidateID string, ttl time.Duration, onClaim []ClaimHandler, ) *Candidate
NewCandidate creates a new Candidate instance to participate in the specified election. The candidateID uniquely identifies this participant. The ttl determines how long a leadership claim remains valid without renewal. The onClaim handlers are invoked when this candidate successfully claims leadership.
func (*Candidate) AddHandlers ¶
func (c *Candidate) AddHandlers(handlers ...ClaimHandler)
func (*Candidate) Error ¶
Error returns a channel that receives errors encountered during election operations such as claim attempts, renewals, or watch failures.
type ClaimHandler ¶
ClaimHandler is a callback function invoked when a candidate successfully claims leadership. Handlers are executed in separate goroutines.
type ElectionStore ¶
type ElectionStore struct {
// contains filtered or unexported fields
}
func NewElectionStore ¶
func NewElectionStore(client *clientv3.Client, root string) *ElectionStore
func (*ElectionStore) Create ¶
func (s *ElectionStore) Create(item *StoredElection) storage.PutOp[*StoredElection]
func (*ElectionStore) Delete ¶
func (s *ElectionStore) Delete(item *StoredElection) storage.DeleteValueOp[*StoredElection]
func (*ElectionStore) GetByKey ¶
func (s *ElectionStore) GetByKey(name Name) storage.GetOp[*StoredElection]
func (*ElectionStore) Key ¶
func (s *ElectionStore) Key(name Name) string
func (*ElectionStore) Update ¶
func (s *ElectionStore) Update(item *StoredElection) storage.PutOp[*StoredElection]
func (*ElectionStore) Watch ¶
func (s *ElectionStore) Watch(name Name) storage.WatchOp[*StoredElection]
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages election operations.
func NewService ¶
func NewService( store *ElectionStore, loggerFactory *logging.Factory, ) *Service
NewService returns a new Service.
func (*Service) NewCandidate ¶
func (s *Service) NewCandidate(electionName Name, candidateID string, ttl time.Duration, onClaim ...ClaimHandler) *Candidate
NewCandidate creates a new Candidate for the given election. candidateID must be unique amongst candidates.