diff options
| author | Paul Buetow <paul@buetow.org> | 2023-06-14 09:52:50 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-06-14 09:52:50 +0300 |
| commit | 8259f1a764e0c3543c6770dc91433d85fb2e96db (patch) | |
| tree | beba47b6be4531fc6966b694bd4dfd1dcb901719 /internal/quorum | |
| parent | 93b32777632eb79393e4f6fe0b752665c8e511ff (diff) | |
make loop interval configurable
Diffstat (limited to 'internal/quorum')
| -rw-r--r-- | internal/quorum/quorum.go | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/internal/quorum/quorum.go b/internal/quorum/quorum.go index 52cf6ee..dfeabe6 100644 --- a/internal/quorum/quorum.go +++ b/internal/quorum/quorum.go @@ -36,17 +36,25 @@ func New(conf config.Config) Quorum { func (quo Quorum) Start(ctx context.Context) <-chan vote.Vote { ch := make(chan vote.Vote) + interval := time.Second * time.Duration(quo.conf.LoopIntervalS) + if vote.Expiry <= interval { + log.Fatal("quorum: LoopIntervalS ", quo.conf.LoopIntervalS, + " should be less than the vote expiry of ", vote.Expiry) + } + go func() { defer close(ch) for { select { - case <-time.After(vote.Expiry): + case <-time.After(interval): myVote, _ := quo.makeMyVote() + log.Println("quorum: made my vote:", myVote) ch <- myVote case v := <-quo.voteCh: quo.vote(v) if myVote, changed := quo.makeMyVote(); changed { + log.Println("quorum: changed my vote:", myVote) ch <- myVote } quo.score() |
