deletes nodes from cache if unresponsive (#1185)

* deletes nodes from cache if unresponsive

* update error messages
This commit is contained in:
Dylan Lott 2019-01-30 14:15:24 -07:00 committed by GitHub
parent 97714d150f
commit 6025f9f19e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -119,22 +119,25 @@ func (discovery *Discovery) refresh(ctx context.Context) error {
for _, node := range list {
ping, err := discovery.kad.Ping(ctx, *node)
if err != nil {
discovery.log.Info("could not pinging node")
discovery.log.Info("could not ping node")
_, err := discovery.statdb.UpdateUptime(ctx, ping.Id, false)
if err != nil {
discovery.log.Error("error updating node uptime in statdb")
discovery.log.Error("could not update node uptime in statdb")
}
err = discovery.cache.Delete(ctx, node.Id)
if err != nil {
discovery.log.Error("deleting unresponsive node from cache:", zap.Error(err))
}
continue
}
_, err = discovery.statdb.UpdateUptime(ctx, ping.Id, true)
if err != nil {
discovery.log.Error("error updating node uptime in statdb")
discovery.log.Error("could not update node uptime in statdb")
}
err = discovery.cache.Put(ctx, ping.Id, ping)
if err != nil {
discovery.log.Error("error putting node into cache")
discovery.log.Error("could not put node into cache")
}
}