From d371c4fbfae2624c2a7ad1b6da33fd7b4c564736 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 14 Jul 2024 21:56:16 +0800 Subject: [PATCH] :sparkles: Keep register func can report error --- pkg/hyper/conn.go | 10 ++++++---- pkg/internal/gap/client.go | 15 --------------- pkg/internal/grpc/services.go | 3 +++ 3 files changed, 9 insertions(+), 19 deletions(-) delete mode 100644 pkg/internal/gap/client.go diff --git a/pkg/hyper/conn.go b/pkg/hyper/conn.go index 80b7422..88cfaf0 100644 --- a/pkg/hyper/conn.go +++ b/pkg/hyper/conn.go @@ -43,15 +43,17 @@ func (v *HyperConn) RegisterService() error { return err } -func (v *HyperConn) KeepRegisterService() { - _ = v.RegisterService() +func (v *HyperConn) KeepRegisterService() error { + err := v.RegisterService() + if err != nil { + return err + } for { time.Sleep(5 * time.Second) client := health.NewHealthClient(v.dealerConn) if _, err := client.Check(context.Background(), &health.HealthCheckRequest{}); err != nil { - v.KeepRegisterService() - return + return v.KeepRegisterService() } } } diff --git a/pkg/internal/gap/client.go b/pkg/internal/gap/client.go deleted file mode 100644 index fb09c1b..0000000 --- a/pkg/internal/gap/client.go +++ /dev/null @@ -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 -} diff --git a/pkg/internal/grpc/services.go b/pkg/internal/grpc/services.go index 85c133a..4c13f81 100644 --- a/pkg/internal/grpc/services.go +++ b/pkg/internal/grpc/services.go @@ -5,6 +5,7 @@ import ( "fmt" "git.solsynth.dev/hydrogen/dealer/pkg/internal/directory" "git.solsynth.dev/hydrogen/dealer/pkg/proto" + "github.com/rs/zerolog/log" "github.com/samber/lo" ) @@ -57,6 +58,7 @@ func (v *Server) AddService(ctx context.Context, info *proto.ServiceInfo) (*prot HttpAddr: info.HttpAddr, } directory.AddServiceInstance(in) + log.Info().Str("id", info.GetId()).Str("label", info.GetLabel()).Msg("New service added.") return &proto.AddServiceResponse{ IsSuccess: true, }, 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) { directory.RemoveServiceInstance(request.GetId()) + log.Info().Str("id", request.GetId()).Msg("A service removed.") return &proto.RemoveServiceResponse{ IsSuccess: true, }, nil