✨ Keep register func can report error
This commit is contained in:
parent
31e73c438e
commit
d371c4fbfa
@ -43,15 +43,17 @@ func (v *HyperConn) RegisterService() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *HyperConn) KeepRegisterService() {
|
func (v *HyperConn) KeepRegisterService() error {
|
||||||
_ = v.RegisterService()
|
err := v.RegisterService()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
client := health.NewHealthClient(v.dealerConn)
|
client := health.NewHealthClient(v.dealerConn)
|
||||||
if _, err := client.Check(context.Background(), &health.HealthCheckRequest{}); err != nil {
|
if _, err := client.Check(context.Background(), &health.HealthCheckRequest{}); err != nil {
|
||||||
v.KeepRegisterService()
|
return v.KeepRegisterService()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
package gap
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
|
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
var H *hyper.HyperConn
|
|
||||||
|
|
||||||
func NewHyperClient(info *proto.ServiceInfo) (err error) {
|
|
||||||
H, err = hyper.NewHyperConn(viper.GetString("dealer.addr"), info)
|
|
||||||
H.KeepRegisterService()
|
|
||||||
return
|
|
||||||
}
|
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/internal/directory"
|
"git.solsynth.dev/hydrogen/dealer/pkg/internal/directory"
|
||||||
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -57,6 +58,7 @@ func (v *Server) AddService(ctx context.Context, info *proto.ServiceInfo) (*prot
|
|||||||
HttpAddr: info.HttpAddr,
|
HttpAddr: info.HttpAddr,
|
||||||
}
|
}
|
||||||
directory.AddServiceInstance(in)
|
directory.AddServiceInstance(in)
|
||||||
|
log.Info().Str("id", info.GetId()).Str("label", info.GetLabel()).Msg("New service added.")
|
||||||
return &proto.AddServiceResponse{
|
return &proto.AddServiceResponse{
|
||||||
IsSuccess: true,
|
IsSuccess: true,
|
||||||
}, nil
|
}, nil
|
||||||
@ -64,6 +66,7 @@ func (v *Server) AddService(ctx context.Context, info *proto.ServiceInfo) (*prot
|
|||||||
|
|
||||||
func (v *Server) RemoveService(ctx context.Context, request *proto.RemoveServiceRequest) (*proto.RemoveServiceResponse, error) {
|
func (v *Server) RemoveService(ctx context.Context, request *proto.RemoveServiceRequest) (*proto.RemoveServiceResponse, error) {
|
||||||
directory.RemoveServiceInstance(request.GetId())
|
directory.RemoveServiceInstance(request.GetId())
|
||||||
|
log.Info().Str("id", request.GetId()).Msg("A service removed.")
|
||||||
return &proto.RemoveServiceResponse{
|
return &proto.RemoveServiceResponse{
|
||||||
IsSuccess: true,
|
IsSuccess: true,
|
||||||
}, nil
|
}, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user