Merge remote-tracking branch 'origin/tuoyun' into tuoyun

This commit is contained in:
Gordon 2022-03-17 15:47:20 +08:00
commit 5dddaeb6e5

View File

@ -78,16 +78,26 @@ func RegisterEtcd(schema, etcdAddr, myHost string, myPort int, serviceName strin
log.Debug("", "KeepAlive kresp ok", pv) log.Debug("", "KeepAlive kresp ok", pv)
} else { } else {
log.Error("", "KeepAlive kresp failed", pv) log.Error("", "KeepAlive kresp failed", pv)
t := time.NewTicker(time.Duration(ttl) * time.Second) t := time.NewTicker(time.Duration(ttl/2) * time.Second)
for { for {
select { select {
case <-t.C: case <-t.C:
} }
ctx, _ := context.WithCancel(context.Background())
resp, err := cli.Grant(ctx, int64(ttl))
if err != nil {
log.Error("", "Grant failed ", err.Error())
continue
}
if _, err := cli.Put(ctx, serviceKey, serviceValue, clientv3.WithLease(resp.ID)); err != nil { if _, err := cli.Put(ctx, serviceKey, serviceValue, clientv3.WithLease(resp.ID)); err != nil {
log.Error("", "etcd Put failed ", err.Error(), serviceKey, serviceValue, resp.ID) log.Error("", "etcd Put failed ", err.Error(), serviceKey, serviceValue, resp.ID)
} continue
} else {
log.Info("", "etcd Put ok", serviceKey, serviceValue, resp.ID) log.Info("", "etcd Put ok", serviceKey, serviceValue, resp.ID)
} }
}
} }
} }
} }