feat(executor/local): set output on executor error
This commit is contained in:
		
							parent
							
								
									b6edc2c571
								
							
						
					
					
						commit
						0954bfdbd0
					
				|  | @ -20,6 +20,7 @@ func (e *Local) generateResult( | ||||||
| 	runTime time.Duration, | 	runTime time.Duration, | ||||||
| 	cmd stage.Cmd, | 	cmd stage.Cmd, | ||||||
| 	stdoutBuffer, stderrBuffer bytes.Buffer, | 	stdoutBuffer, stderrBuffer bytes.Buffer, | ||||||
|  | 	isTimeout bool, | ||||||
| ) stage.ExecutorResult { | ) stage.ExecutorResult { | ||||||
| 	result := stage.ExecutorResult{ | 	result := stage.ExecutorResult{ | ||||||
| 		Status:     stage.StatusAccepted, | 		Status:     stage.StatusAccepted, | ||||||
|  | @ -65,6 +66,9 @@ func (e *Local) generateResult( | ||||||
| 			result.Error = err.Error() | 			result.Error = err.Error() | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	if isTimeout { | ||||||
|  | 		result.Status = stage.StatusTimeLimitExceeded | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	if cmd.Stdout != nil && cmd.Stdout.Name != nil { | 	if cmd.Stdout != nil && cmd.Stdout.Name != nil { | ||||||
| 		result.Files[*cmd.Stdout.Name] = stdoutBuffer.String() | 		result.Files[*cmd.Stdout.Name] = stdoutBuffer.String() | ||||||
|  | @ -122,9 +126,8 @@ func (e *Local) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) { | ||||||
| 			done <- execCmd.Wait() | 			done <- execCmd.Wait() | ||||||
| 		}() | 		}() | ||||||
| 
 | 
 | ||||||
| 		if cmd.ClockLimit > 0 { |  | ||||||
| 		var duration time.Duration | 		var duration time.Duration | ||||||
| 			if cmd.ClockLimit > uint64(math.MaxInt64) { | 		if cmd.ClockLimit > uint64(math.MaxInt64) || cmd.ClockLimit <= 0 { | ||||||
| 			duration = time.Duration(math.MaxInt64) | 			duration = time.Duration(math.MaxInt64) | ||||||
| 		} else { | 		} else { | ||||||
| 			duration = time.Duration(cmd.ClockLimit) * time.Nanosecond // #nosec G115
 | 			duration = time.Duration(cmd.ClockLimit) * time.Nanosecond // #nosec G115
 | ||||||
|  | @ -140,29 +143,19 @@ func (e *Local) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) { | ||||||
| 				cmd, | 				cmd, | ||||||
| 				stdoutBuffer, | 				stdoutBuffer, | ||||||
| 				stderrBuffer, | 				stderrBuffer, | ||||||
|  | 				false, | ||||||
| 			) | 			) | ||||||
| 			results = append(results, result) | 			results = append(results, result) | ||||||
| 		case <-time.After(duration): | 		case <-time.After(duration): | ||||||
| 			_ = execCmd.Process.Kill() | 			_ = execCmd.Process.Kill() | ||||||
| 				result := stage.ExecutorResult{ |  | ||||||
| 					Status:  stage.StatusTimeLimitExceeded, |  | ||||||
| 					Error:   "", |  | ||||||
| 					Files:   map[string]string{}, |  | ||||||
| 					FileIDs: map[string]string{}, |  | ||||||
| 				} |  | ||||||
| 				results = append(results, result) |  | ||||||
| 			} |  | ||||||
| 		} else { |  | ||||||
| 			err := <-done |  | ||||||
| 			endTime := time.Now() |  | ||||||
| 			runTime := endTime.Sub(startTime) |  | ||||||
| 			result := e.generateResult( | 			result := e.generateResult( | ||||||
| 				err, | 				nil, | ||||||
| 				execCmd.ProcessState, | 				execCmd.ProcessState, | ||||||
| 				runTime, | 				duration, | ||||||
| 				cmd, | 				cmd, | ||||||
| 				stdoutBuffer, | 				stdoutBuffer, | ||||||
| 				stderrBuffer, | 				stderrBuffer, | ||||||
|  | 				true, | ||||||
| 			) | 			) | ||||||
| 			results = append(results, result) | 			results = append(results, result) | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user