MCPcopy Create free account
hub / github.com/DoNewsCode/core / Campaign

Method Campaign

leader/election.go:42–50  ·  view source on GitHub ↗

Campaign starts a leader election. It will block until this node becomes a leader or context cancelled.

(ctx context.Context)

Source from the content-addressed store, hash-verified

40
41// Campaign starts a leader election. It will block until this node becomes a leader or context cancelled.
42func (e *Election) Campaign(ctx context.Context) error {
43 if err := e.driver.Campaign(ctx); err != nil {
44 return fmt.Errorf("not elected: %w", err)
45 }
46 e.status.isLeader.Store(true)
47 // trigger events
48 e.dispatcher.Dispatch(ctx, OnStatusChanged, OnStatusChangedPayload{Status: e.status})
49 return nil
50}
51
52// Resign gives up the leadership.
53func (e *Election) Resign(ctx context.Context) error {

Callers 2

TestElectionFunction · 0.95
TestElectionFunction · 0.95

Calls 2

CampaignMethod · 0.65
DispatchMethod · 0.65

Tested by 2

TestElectionFunction · 0.76
TestElectionFunction · 0.76