Skip to content

Commit

Permalink
Check balance at monitoring start
Browse files Browse the repository at this point in the history
We added a check execution at start of the monitoring. Previously we had
to wait for ticker to invoke the first check.
  • Loading branch information
nkuba committed Sep 1, 2021
1 parent 26fdfa2 commit f17cc48
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/chain/ethlike/balance_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,21 @@ func (bm *BalanceMonitor) Observe(
ticker := time.NewTicker(tick)
defer ticker.Stop()

checkBalance := func() {
err := wrappers.DoWithDefaultRetry(retryTimeout, check)
if err != nil {
logger.Errorf("balance monitor error: [%v]", err)
}
}

// Initial balance check at monitoring start.
checkBalance()

for {
select {
// Balance check at ticks.
case <-ticker.C:
err := wrappers.DoWithDefaultRetry(retryTimeout, check)

logger.Errorf("balance monitor error: [%v]", err)
checkBalance()
case <-ctx.Done():
return
}
Expand Down

0 comments on commit f17cc48

Please sign in to comment.