mirror of
https://github.com/absmach/supermq.git
synced 2026-06-23 07:40:17 +00:00
MG-2235 - Check gRPC service is healthy during setup (#2245)
Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
This commit is contained in:
@@ -18,16 +18,17 @@ import (
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/health"
|
||||
grpchealth "google.golang.org/grpc/health/grpc_health_v1"
|
||||
)
|
||||
|
||||
const (
|
||||
stopWaitTime = 5 * time.Second
|
||||
)
|
||||
const stopWaitTime = 5 * time.Second
|
||||
|
||||
type Server struct {
|
||||
server.BaseServer
|
||||
server *grpc.Server
|
||||
registerService serviceRegister
|
||||
health *health.Server
|
||||
}
|
||||
|
||||
type serviceRegister func(srv *grpc.Server)
|
||||
@@ -116,7 +117,10 @@ func (s *Server) Start() error {
|
||||
grpcServerOptions = append(grpcServerOptions, creds)
|
||||
|
||||
s.server = grpc.NewServer(grpcServerOptions...)
|
||||
s.health = health.NewServer()
|
||||
grpchealth.RegisterHealthServer(s.server, s.health)
|
||||
s.registerService(s.server)
|
||||
s.health.SetServingStatus(s.Name, grpchealth.HealthCheckResponse_SERVING)
|
||||
|
||||
go func() {
|
||||
errCh <- s.server.Serve(listener)
|
||||
@@ -136,6 +140,7 @@ func (s *Server) Stop() error {
|
||||
c := make(chan bool)
|
||||
go func() {
|
||||
defer close(c)
|
||||
s.health.Shutdown()
|
||||
s.server.GracefulStop()
|
||||
}()
|
||||
select {
|
||||
|
||||
Reference in New Issue
Block a user