Skip to content

Commit

Permalink
Allow setting leadership extra functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed Jul 8, 2019
1 parent 0c38604 commit c6da283
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dkron/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ type Agent struct {
peers map[string][]*serverParts
localPeers map[raft.ServerAddress]*serverParts
peerLock sync.RWMutex

establishLeadershipFuncs []func() error
revokeLeadershipFuncs []func() error
}

// ProcessorFactory is a function type that creates a new instance
Expand Down
12 changes: 12 additions & 0 deletions dkron/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ func (a *Agent) establishLeadership(stopCh chan struct{}) error {
defer metrics.MeasureSince([]string{"dkron", "leader", "establish_leadership"}, time.Now())
a.schedule()

for _, f := range a.establishLeadershipFuncs {
if err := f(); err != nil {
return err
}
}

return nil
}

Expand All @@ -197,6 +203,12 @@ func (a *Agent) revokeLeadership() error {
defer metrics.MeasureSince([]string{"dkron", "leader", "revoke_leadership"}, time.Now())
a.sched.Stop()

for _, f := range a.revokeLeadershipFuncs {
if err := f(); err != nil {
return err
}
}

return nil
}

Expand Down

0 comments on commit c6da283

Please sign in to comment.