Add check for liveness

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Travis Person 2019-10-17 14:36:08 -07:00 committed by Jakub Sztandera
parent 0b2718a4af
commit 09341d0440
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA

View File

@ -76,6 +76,8 @@ func GetTips(ctx context.Context, api api.FullNode, lastHeight uint64) (<-chan *
go func() {
defer close(chmain)
ping := time.Tick(30 * time.Second)
for {
select {
case changes := <-notif:
@ -97,6 +99,18 @@ func GetTips(ctx context.Context, api api.FullNode, lastHeight uint64) (<-chan *
chmain <- change.Val
}
}
case <-ping:
log.Print("Running health check")
cctx, cancel := context.WithTimeout(ctx, 5*time.Second)
if _, err := api.ID(cctx); err != nil {
log.Print("Health check failed")
return
}
cancel()
log.Print("Node online")
case <-ctx.Done():
return
}