JOJ3/internal/parser/healthcheck/parser.go
张泊明518370910136 5c6915ad36
Some checks failed
build / trigger-build-image (push) Blocked by required conditions
build / build (push) Has been cancelled
submodules sync / sync (push) Has been cancelled
chore: remove period in short sentences
2024-11-10 01:01:10 -05:00

51 lines
1.2 KiB
Go

package healthcheck
import (
"fmt"
"github.com/criyle/go-judge/envexec"
"github.com/joint-online-judge/JOJ3/internal/stage"
)
type Healthcheck struct{}
type Conf struct {
Stdout string `default:"stdout"`
Stderr string `default:"stderr"`
}
func Parse(executorResult stage.ExecutorResult, conf Conf) (stage.ParserResult, bool) {
stdout := executorResult.Files[conf.Stdout]
stderr := executorResult.Files[conf.Stderr]
if executorResult.Status != stage.Status(envexec.StatusAccepted) {
return stage.ParserResult{
Score: 0,
Comment: fmt.Sprintf(
"Unexpected executor status: `%s`\n`stdout`:\n```%s\n```\n`stderr`:\n```%s\n```",
executorResult.Status, stdout, stderr,
),
}, true
}
return stage.ParserResult{
Score: 0,
Comment: stdout,
}, stdout != ""
}
func (*Healthcheck) Run(results []stage.ExecutorResult, confAny any) (
[]stage.ParserResult, bool, error,
) {
conf, err := stage.DecodeConf[Conf](confAny)
if err != nil {
return nil, true, err
}
var res []stage.ParserResult
forceQuit := false
for _, result := range results {
parserResult, forceQuitResult := Parse(result, *conf)
res = append(res, parserResult)
forceQuit = forceQuit || forceQuitResult
}
return res, forceQuit, nil
}