Skip to content

Commit

Permalink
Merge pull request #37 from h0n9/feature/36_gracefully-shutdown-lake-…
Browse files Browse the repository at this point in the history
…service

Gracefully shutdown lake service
  • Loading branch information
h0n9 authored Aug 3, 2023
2 parents ac46fd1 + 5508dfc commit f519b85
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 10 additions & 2 deletions cli/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ var Cmd = &cobra.Command{
ctx, cancel := context.WithCancel(context.Background())
logger.Info().Msg("initalized context")

var grpcServer *grpc.Server = nil
var (
lakeService *lake.Service = nil
grpcServer *grpc.Server = nil
)

sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
Expand All @@ -64,14 +67,19 @@ var Cmd = &cobra.Command{
cancel()
if grpcServer != nil {
grpcServer.GracefulStop()
logger.Info().Msg("gracefully stopped gRPC server")
}
if lakeService != nil {
lakeService.Close()
logger.Info().Msg("closed lake service")
}
wg.Done()
}()
logger.Info().Msg("listening os signal: SIGINT, SIGTERM")

grpcServer = grpc.NewServer()
logger.Info().Msg("initalized gRPC server")
lakeService, err := lake.NewService(
lakeService, err = lake.NewService(
ctx,
&logger,
[]byte(seed),
Expand Down
1 change: 0 additions & 1 deletion lake/lake.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func (service *Service) Close() {
if service.relayer != nil {
service.relayer.Close()
}
service.logger.Info().Msg("closed lake service")
}

func (service *Service) Publish(ctx context.Context, req *pb.PublishReq) (*pb.PublishRes, error) {
Expand Down

0 comments on commit f519b85

Please sign in to comment.