// Delete the initial process and container
Delete the initial process and container
// Delete the initial process and container
func (s *service) Delete(ctx context.Context, r *taskAPI.DeleteRequest) (_ *taskAPI.DeleteResponse, err error) {
	start := time.Now()
	defer func() {
		err = toGRPC(err)
		rpcDurationsHistogram.WithLabelValues("delete").Observe(float64(time.Since(start).Nanoseconds() / int64(time.Millisecond)))
	}()
	s.mu.Lock()
	defer s.mu.Unlock()
	c, err := s.getContainer(r.ID)
	if err != nil {
		return nil, err
	}
	if r.ExecID == "" {
		if err = deleteContainer(ctx, s, c); err != nil {
			return nil, err
		}
		s.send(&eventstypes.TaskDelete{
			ContainerID: c.id,
			Pid:         s.pid,
			ExitStatus:  c.exit,
			ExitedAt:    c.exitTime,
		})
		return &taskAPI.DeleteResponse{
			ExitStatus: c.exit,
			ExitedAt:   c.exitTime,
			Pid:        s.pid,
		}, nil
	}
	execs, err := c.getExec(r.ExecID)
	if err != nil {
		return nil, err
	}
	delete(c.execs, r.ExecID)
	return &taskAPI.DeleteResponse{
		ExitStatus: uint32(execs.exitCode),
		ExitedAt:   execs.exitTime,
		Pid:        s.pid,
	}, nil
}
func ( s * service ) Delete ( ctx context . Context , r * taskAPI . DeleteRequest ) ( _ * taskAPI . DeleteResponse , err error ) { start := time . Now ( ) defer func ( ) { err = toGRPC ( err ) rpcDurationsHistogram . WithLabelValues ( " " ) . Observe ( float64 ( time . Since ( start ) . Nanoseconds ( ) / int64 ( time . Millisecond ) ) ) } ( ) s . mu . Lock ( ) defer s . mu . Unlock ( ) c , err := s . getContainer ( r . ID ) if err != nil { return nil , err } if r . ExecID == " " { if err = deleteContainer ( ctx , s , c ) ; err != nil { return nil , err } s . send ( & eventstypes . TaskDelete { ContainerID : c . id , Pid : s . pid , ExitStatus : c . exit , ExitedAt : c . exitTime , } ) return & taskAPI . DeleteResponse { ExitStatus : c . exit , ExitedAt : c . exitTime , Pid : s . pid , } , nil } execs , err := c . getExec ( r . ExecID ) if err != nil { return nil , err } delete ( c . execs , r . ExecID ) return & taskAPI . DeleteResponse { ExitStatus : uint32 ( execs . exitCode ) , ExitedAt : execs . exitTime , Pid : s . pid , } , nil }
Delete the initial process and container
Delete the initial process and container
//deal with the exec case