feat(cmd/joj3): run teapot commands in goroutine
This commit is contained in:
parent
4e3d202fa9
commit
d934e9a067
|
@ -7,6 +7,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
|
"github.com/joint-online-judge/JOJ3/cmd/joj3/conf"
|
||||||
)
|
)
|
||||||
|
@ -33,55 +34,61 @@ func Run(conf *conf.Conf) error {
|
||||||
repoParts := strings.Split(repository, "/")
|
repoParts := strings.Split(repository, "/")
|
||||||
repoName := repoParts[1]
|
repoName := repoParts[1]
|
||||||
re := regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]`)
|
re := regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]`)
|
||||||
if !conf.Teapot.SkipScoreboard {
|
execCommand := func(name string, cmdArgs []string) error {
|
||||||
cmd := exec.Command("joint-teapot", "joj3-scoreboard",
|
cmd := exec.Command(name, cmdArgs...) // #nosec G204
|
||||||
envFilePath, conf.Stage.OutputPath, actor, conf.Teapot.GradingRepoName,
|
|
||||||
repoName, runNumber, conf.Teapot.ScoreboardPath, conf.Name) // #nosec G204
|
|
||||||
outputBytes, err := cmd.CombinedOutput()
|
outputBytes, err := cmd.CombinedOutput()
|
||||||
output := re.ReplaceAllString(string(outputBytes), "")
|
output := re.ReplaceAllString(string(outputBytes), "")
|
||||||
for _, line := range strings.Split(output, "\n") {
|
for _, line := range strings.Split(output, "\n") {
|
||||||
if line == "" {
|
if line == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
slog.Info("joint-teapot joj3-scoreboard", "output", line)
|
slog.Info(fmt.Sprintf("%s %s", name, cmdArgs[0]), "output", line)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
slog.Error("joint-teapot joj3-scoreboard", "err", err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
var scoreboardErr, failedTableErr, issueErr error
|
||||||
|
wg.Add(2)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
if !conf.Teapot.SkipScoreboard {
|
||||||
|
err := execCommand("joint-teapot", []string{
|
||||||
|
"joj3-scoreboard", envFilePath, conf.Stage.OutputPath, actor,
|
||||||
|
conf.Teapot.GradingRepoName, repoName, runNumber,
|
||||||
|
conf.Teapot.ScoreboardPath, conf.Name,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
scoreboardErr = err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !conf.Teapot.SkipFailedTable {
|
if !conf.Teapot.SkipFailedTable {
|
||||||
cmd := exec.Command("joint-teapot", "joj3-failed-table",
|
err := execCommand("joint-teapot", []string{
|
||||||
envFilePath, conf.Stage.OutputPath, actor, conf.Teapot.GradingRepoName,
|
"joj3-failed-table", envFilePath, conf.Stage.OutputPath, actor,
|
||||||
repoName, runNumber, conf.Teapot.FailedTablePath, conf.Name) // #nosec G204
|
conf.Teapot.GradingRepoName, repoName, runNumber,
|
||||||
outputBytes, err := cmd.CombinedOutput()
|
conf.Teapot.FailedTablePath, conf.Name,
|
||||||
output := re.ReplaceAllString(string(outputBytes), "")
|
})
|
||||||
for _, line := range strings.Split(output, "\n") {
|
|
||||||
if line == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
slog.Info("joint-teapot joj3-failed-table", "output", line)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("joint-teapot joj3-failed-table", "err", err)
|
failedTableErr = err
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
if !conf.Teapot.SkipIssue {
|
if !conf.Teapot.SkipIssue {
|
||||||
cmd := exec.Command("joint-teapot", "joj3-create-result-issue",
|
err := execCommand("joint-teapot", []string{
|
||||||
envFilePath, conf.Stage.OutputPath, repoName, runNumber, conf.Name) // #nosec G204
|
"joj3-create-result-issue", envFilePath, conf.Stage.OutputPath,
|
||||||
outputBytes, err := cmd.CombinedOutput()
|
repoName, runNumber, conf.Name,
|
||||||
output := re.ReplaceAllString(string(outputBytes), "")
|
})
|
||||||
for _, line := range strings.Split(output, "\n") {
|
|
||||||
if line == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
slog.Info("joint-teapot joj3-create-result-issue", "output", line)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error("joint-teapot joj3-create-result-issue", "err", err)
|
issueErr = err
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
wg.Wait()
|
||||||
|
if scoreboardErr != nil || failedTableErr != nil || issueErr != nil {
|
||||||
|
slog.Error("teapot exit", "scoreboardErr", scoreboardErr,
|
||||||
|
"failedTableErr", failedTableErr, "issueErr", issueErr)
|
||||||
|
return fmt.Errorf("teapot exit")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user