// State returns runtime state information for a process
State returns runtime state information for a process
// State returns runtime state information for a process
func (s *service) State(ctx context.Context, r *taskAPI.StateRequest) (_ *taskAPI.StateResponse, err error) {
	start := time.Now()
	defer func() {
		err = toGRPC(err)
		rpcDurationsHistogram.WithLabelValues("state").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 == "" {
		return &taskAPI.StateResponse{
			ID:         c.id,
			Bundle:     c.bundle,
			Pid:        s.pid,
			Status:     c.status,
			Stdin:      c.stdin,
			Stdout:     c.stdout,
			Stderr:     c.stderr,
			Terminal:   c.terminal,
			ExitStatus: c.exit,
		}, nil
	}
	execs, err := c.getExec(r.ExecID)
	if err != nil {
		return nil, err
	}
	return &taskAPI.StateResponse{
		ID:         execs.id,
		Bundle:     c.bundle,
		Pid:        s.pid,
		Status:     execs.status,
		Stdin:      execs.tty.stdin,
		Stdout:     execs.tty.stdout,
		Stderr:     execs.tty.stderr,
		Terminal:   execs.tty.terminal,
		ExitStatus: uint32(execs.exitCode),
	}, nil
}
func ( s * service ) State ( ctx context . Context , r * taskAPI . StateRequest ) ( _ * taskAPI . StateResponse , 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 == " " { return & taskAPI . StateResponse { ID : c . id , Bundle : c . bundle , Pid : s . pid , Status : c . status , Stdin : c . stdin , Stdout : c . stdout , Stderr : c . stderr , Terminal : c . terminal , ExitStatus : c . exit , } , nil } execs , err := c . getExec ( r . ExecID ) if err != nil { return nil , err } return & taskAPI . StateResponse { ID : execs . id , Bundle : c . bundle , Pid : s . pid , Status : execs . status , Stdin : execs . tty . stdin , Stdout : execs . tty . stdout , Stderr : execs . tty . stderr , Terminal : execs . tty . terminal , ExitStatus : uint32 ( execs . exitCode ) , } , nil }
State returns runtime state information for a process
State returns runtime state information for a process
//deal with exec case