Add a context to the updater

Signed-off-by: Sachin Kamboj <skamboj1@bloomberg.net>
This commit is contained in:
Sachin Kamboj
2020-04-06 19:41:43 -04:00
parent aa7eaca30e
commit 3a6ab53ced

View File

@@ -15,6 +15,7 @@
package goldpinger
import (
"context"
"fmt"
"log"
"time"
@@ -26,10 +27,14 @@ func StartUpdater() {
return
}
updateInterval := time.Duration(GoldpingerConfig.RefreshInterval) * time.Second
// start the updater
go func() {
for {
results := PingAllPods(SelectPods())
ctx, cancel := context.WithTimeout(context.Background(), updateInterval)
results := PingAllPods(ctx, SelectPods())
var troublemakers []string
for podIP, value := range results.PodResults {
if *value.OK != true {
@@ -39,7 +44,9 @@ func StartUpdater() {
if len(troublemakers) > 0 {
log.Println("Updater ran into trouble with these peers: ", troublemakers)
}
time.Sleep(time.Duration(GoldpingerConfig.RefreshInterval) * time.Second)
cancel()
time.Sleep(updateInterval)
}
}()
}