feat(executor/sandbox): send all cmds at once
This commit is contained in:
		
							parent
							
								
									07cbf29792
								
							
						
					
					
						commit
						6215b7d7af
					
				|  | @ -21,7 +21,6 @@ func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) { | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	// cannot use range loop since we need to change the value
 | 	// 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 { | 	for i := 0; i < len(cmds); i += 1 { | ||||||
| 		cmd := &cmds[i] | 		cmd := &cmds[i] | ||||||
| 		if cmd.CopyIn == nil { | 		if cmd.CopyIn == nil { | ||||||
|  | @ -32,25 +31,23 @@ func (e *Sandbox) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) { | ||||||
| 				cmd.CopyIn[k] = stage.CmdFile{FileID: &fileID} | 				cmd.CopyIn[k] = stage.CmdFile{FileID: &fileID} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 		// NOTE: send all cmds at once may cause oom, no idea on why
 | 	} | ||||||
| 		pbCmd := convertPBCmd([]stage.Cmd{*cmd}) | 	pbCmds := convertPBCmd(cmds) | ||||||
| 		pbReq := &pb.Request{Cmd: pbCmd} | 	for i, pbCmd := range pbCmds { | ||||||
| 		slog.Debug("sandbox execute", "i", i, "pbReq size", proto.Size(pbReq)) | 		slog.Debug("sandbox execute", "i", i, "pbCmd size", proto.Size(pbCmd)) | ||||||
| 		pbRet, err := e.execClient.Exec(context.TODO(), pbReq) | 	} | ||||||
| 		if err != nil { | 	pbReq := &pb.Request{Cmd: pbCmds} | ||||||
| 			return nil, err | 	slog.Debug("sandbox execute", "pbReq size", proto.Size(pbReq)) | ||||||
| 		} | 	pbRet, err := e.execClient.Exec(context.TODO(), pbReq) | ||||||
| 		slog.Debug("sandbox execute", "i", i, "pbRet size", proto.Size(pbRet)) | 	if err != nil { | ||||||
| 		if pbRet.Error != "" { | 		return nil, err | ||||||
| 			return nil, fmt.Errorf("sandbox execute error: %s", pbRet.Error) | 	} | ||||||
| 		} | 	if pbRet.Error != "" { | ||||||
| 		if len(pbRet.Results) == 0 { | 		return nil, fmt.Errorf("sandbox execute error: %s", pbRet.Error) | ||||||
| 			return nil, fmt.Errorf("sandbox execute error: no result") | 	} | ||||||
| 		} | 	results := convertPBResult(pbRet.Results) | ||||||
| 		result := convertPBResult(pbRet.Results)[0] | 	for _, result := range results { | ||||||
| 		slog.Debug("sandbox execute", "i", i, "result", result) |  | ||||||
| 		maps.Copy(e.cachedMap, result.FileIDs) | 		maps.Copy(e.cachedMap, result.FileIDs) | ||||||
| 		results[i] = result |  | ||||||
| 	} | 	} | ||||||
| 	return results, nil | 	return results, nil | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user