Skip to content

Commit

Permalink
[aggregator] Fix checkCampaignStateLoop (#2867)
Browse files Browse the repository at this point in the history
  • Loading branch information
vdarulis authored Nov 10, 2020
1 parent 2d8dfe5 commit 47cde34
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions src/aggregator/aggregator/election_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,33 +572,28 @@ func (mgr *electionManager) campaignState() campaignState {
return mgr.campaignStateWatchable.Get().(campaignState)
}

func (mgr *electionManager) checkCampaignState() {
enabled, err := mgr.campaignIsEnabledFn()
if err != nil {
mgr.metrics.campaignCheckErrors.Inc(1)
return
}
newState := newCampaignState(enabled)
currState := mgr.campaignState()
if currState == newState {
return
}
mgr.processCampaignStateChange(newState)
}

func (mgr *electionManager) checkCampaignStateLoop() {
defer mgr.Done()

ticker := time.NewTicker(mgr.campaignStateCheckInterval)
defer ticker.Stop()

for {
select {
case <-mgr.doneCh:
return
default:
}

enabled, err := mgr.campaignIsEnabledFn()
if err != nil {
mgr.metrics.campaignCheckErrors.Inc(1)

continue
}
newState := newCampaignState(enabled)
currState := mgr.campaignState()
if currState == newState {
continue
}
mgr.processCampaignStateChange(newState)

// block on ticker or exit signal
mgr.checkCampaignState()
select {
case <-ticker.C:
case <-mgr.doneCh:
Expand Down

0 comments on commit 47cde34

Please sign in to comment.