From df2ade4988f9845f19d019fa0bed3e8fcbf93478 Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Sat, 5 Apr 2025 05:14:16 -0400 Subject: [PATCH] feat(executor/sandbox): 1 cmd each time --- internal/executor/sandbox/executor.go | 30 +++++++++++++-------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/internal/executor/sandbox/executor.go b/internal/executor/sandbox/executor.go index dda11bb..4f36ec6 100644 --- a/internal/executor/sandbox/executor.go +++ b/internal/executor/sandbox/executor.go @@ -21,6 +21,7 @@ func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) { } } // cannot use range loop since we need to change the value + results := make([]stage.ExecutorResult, len(cmds)) for i := 0; i < len(cmds); i += 1 { cmd := &cmds[i] if cmd.CopyIn == nil { @@ -31,23 +32,20 @@ func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) { cmd.CopyIn[k] = stage.CmdFile{FileID: &fileID} } } - } - pbCmds := convertPBCmd(cmds) - for i, pbCmd := range pbCmds { - slog.Debug("sandbox execute", "i", i, "pbCmd size", proto.Size(pbCmd)) - } - pbReq := &pb.Request{Cmd: pbCmds} - slog.Debug("sandbox execute", "pbReq size", proto.Size(pbReq)) - pbRet, err := e.execClient.Exec(context.TODO(), pbReq) - if err != nil { - return nil, err - } - if pbRet.Error != "" { - return nil, fmt.Errorf("sandbox execute error: %s", pbRet.Error) - } - results := convertPBResult(pbRet.Results) - for _, result := range results { + pbCmd := convertPBCmd([]stage.Cmd{*cmd}) + slog.Debug("sandbox execute", "i", i, "pbCmd size", proto.Size(pbCmd[0])) + pbReq := &pb.Request{Cmd: pbCmd} + slog.Debug("sandbox execute", "pbReq size", proto.Size(pbReq)) + pbRet, err := e.execClient.Exec(context.TODO(), pbReq) + if err != nil { + return nil, err + } + if pbRet.Error != "" { + return nil, fmt.Errorf("sandbox execute error: %s", pbRet.Error) + } + result := convertPBResult(pbRet.Results)[0] maps.Copy(e.cachedMap, result.FileIDs) + results[i] = result } return results, nil }