Compare commits

...

2 Commits

Author SHA1 Message Date
5abda79a54
feat(parser/file): force quit on non empty conf
All checks were successful
submodules sync / sync (push) Successful in 46s
build / build (push) Successful in 1m34s
build / trigger-build-image (push) Successful in 10s
2024-12-04 06:35:39 -05:00
868154b440
feat(executor/local): full result state 2024-12-04 06:30:44 -05:00
2 changed files with 30 additions and 5 deletions

View File

@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"strings"
"syscall"
"time"
"github.com/criyle/go-judge/envexec"
@ -52,11 +53,31 @@ func (e *Local) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) {
err = execCmd.Wait()
endTime := time.Now()
runTime := endTime.Sub(startTime)
processState := execCmd.ProcessState
result := stage.ExecutorResult{
Status: stage.Status(envexec.StatusAccepted),
ExitStatus: 0,
ExitStatus: processState.ExitCode(),
Error: "",
Time: func() uint64 {
nanos := processState.UserTime().Nanoseconds()
if nanos < 0 {
return 0
}
return uint64(nanos)
}(),
Memory: func() uint64 {
usage := processState.SysUsage()
rusage, ok := usage.(*syscall.Rusage)
if !ok {
return 0
}
maxRssKB := rusage.Maxrss
maxRssBytes := maxRssKB * 1024
if maxRssBytes < 0 {
return 0
}
return uint64(maxRssBytes)
}(),
RunTime: func() uint64 {
nanos := runTime.Nanoseconds()
if nanos < 0 {
@ -70,7 +91,6 @@ func (e *Local) Run(cmds []stage.Cmd) ([]stage.ExecutorResult, error) {
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
result.ExitStatus = exitErr.ExitCode()
result.Status = stage.Status(envexec.StatusNonzeroExitStatus)
result.Error = exitErr.Error()
} else {

View File

@ -7,7 +7,8 @@ import (
)
type Conf struct {
Name string
Name string
ForceQuitOnNonEmpty bool
}
type File struct{}
@ -20,12 +21,16 @@ func (*File) Run(results []stage.ExecutorResult, confAny any) (
return nil, true, err
}
var res []stage.ParserResult
forceQuit := false
for _, result := range results {
content := result.Files[conf.Name]
if conf.ForceQuitOnNonEmpty && content != "" {
forceQuit = true
}
if !strings.HasSuffix(content, "\n") {
content += "\n"
}
res = append(res, stage.ParserResult{Score: 0, Comment: content})
}
return res, false, nil
return res, forceQuit, nil
}