Skip to content

Commit

Permalink
sink-server: update Shutdown interface method, update server shutdown…
Browse files Browse the repository at this point in the history
… sequence
  • Loading branch information
colindickson committed Nov 29, 2023
1 parent 20bb46f commit 9bf67a0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 3 additions & 1 deletion sink-server/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,9 +499,10 @@ func toDuration(in time.Duration) *types.Duration {
return deref(types.Duration(in))
}

func (e *DockerEngine) Shutdown(ctx context.Context, zlog *zap.Logger) (err error) {
func (e *DockerEngine) Shutdown(ctx context.Context, _ error, zlog *zap.Logger) error {
e.mutex.Lock()
defer e.mutex.Unlock()

deps, err := e.list(ctx, zlog)
if err != nil {
return fmt.Errorf("cannot list deployments: %w", err)
Expand All @@ -515,6 +516,7 @@ func (e *DockerEngine) Shutdown(ctx context.Context, zlog *zap.Logger) (err erro
err = errors.Join(err, e)
}
}

return err
}

Expand Down
2 changes: 1 addition & 1 deletion sink-server/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Engine interface {
Info(ctx context.Context, deploymentID string, zlog *zap.Logger) (*pbsinksvc.InfoResponse, error)
List(ctx context.Context, zlog *zap.Logger) ([]*pbsinksvc.DeploymentWithStatus, error)

Shutdown(ctx context.Context, zlog *zap.Logger) error
Shutdown(ctx context.Context, err error, zlog *zap.Logger) error
}

var _ Engine = &docker.DockerEngine{}
9 changes: 7 additions & 2 deletions sink-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ func (s *server) Run(ctx context.Context) {
addr := strings.ReplaceAll(s.httpListenAddr, "*", "")

s.OnTerminating(func(err error) {
time.Sleep(time.Second)
shutdownErr := s.engine.Shutdown(ctx, err, s.logger)
if shutdownErr != nil {
s.logger.Warn("failed to shutdown engine", zap.Error(shutdownErr))
}

time.Sleep(1 * time.Second)

s.logger.Info("shutting down connect web server")
srv.Shutdown(nil)
s.engine.Shutdown(ctx, s.logger)
})

srv.Launch(addr)
Expand Down

0 comments on commit 9bf67a0

Please sign in to comment.