MCPcopy Create free account
hub / github.com/convox/rack / ProcessExec

Method ProcessExec

sdk/methods.go:498–574  ·  view source on GitHub ↗
(app string, pid string, command string, rw io.ReadWriter, opts structs.ProcessExecOptions)

Source from the content-addressed store, hash-verified

496}
497
498func (c *Client) ProcessExec(app string, pid string, command string, rw io.ReadWriter, opts structs.ProcessExecOptions) (int, error) {
499 var err error
500
501 ro, err := stdsdk.MarshalOptions(opts)
502 if err != nil {
503 return 0, err
504 }
505
506 ro.Headers["command"] = command
507 ro.Body = rw
508
509 ws, err := c.Websocket(fmt.Sprintf("/apps/%s/processes/%s/exec", app, pid), ro)
510 if err != nil {
511 return 0, err
512 }
513 defer ws.Close()
514
515 buf := make([]byte, 10*1024)
516 code := 0
517 first := true
518 var ecsSessionData []byte
519
520 for {
521 n, err := ws.Read(buf)
522 if err == io.EOF {
523 if ecsSessionData != nil {
524 return -1, fmt.Errorf("ECS Exec session ended before it was established; please retry")
525 }
526 return code, nil
527 }
528 if err != nil {
529 return code, err
530 }
531
532 if ecsSessionData != nil {
533 ecsSessionData = append(ecsSessionData, buf[0:n]...)
534 var session ecsExecSession
535 if err := json.Unmarshal(ecsSessionData, &session); err != nil {
536 continue
537 }
538 return runSessionManagerPlugin(session)
539 }
540
541 if first {
542 first = false
543 if n > 0 && buf[0] == ecsExecSessionByte {
544 ecsSessionData = make([]byte, 0, n)
545 ecsSessionData = append(ecsSessionData, buf[1:n]...)
546 var session ecsExecSession
547 if err := json.Unmarshal(ecsSessionData, &session); err != nil {
548 continue
549 }
550 return runSessionManagerPlugin(session)
551 }
552 }
553
554 data := string(buf[0:n])
555

Callers

nothing calls this directly

Calls 4

WebsocketMethod · 0.95
runSessionManagerPluginFunction · 0.85
WriteMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected