woj-server/internal/api/runner/build.go

52 lines
1.3 KiB
Go
Raw Normal View History

package runner
import (
"context"
"encoding/json"
"fmt"
2023-07-14 21:47:11 +08:00
"git.0x7f.app/WOJ/woj-server/internal/e"
"git.0x7f.app/WOJ/woj-server/internal/model"
"github.com/hibiken/asynq"
"go.uber.org/zap"
"time"
)
func (h *handler) Build(_ context.Context, t *asynq.Task) error {
var p model.ProblemBuildPayload
if err := json.Unmarshal(t.Payload(), &p); err != nil {
return fmt.Errorf("json.Unmarshal failed: %v: %w", err, asynq.SkipRetry)
}
h.log.Info("build", zap.Any("payload", p))
status, ctx := func() (e.Status, string) {
url, status := h.storageService.Get(p.StorageKey, time.Second*60*5)
if status != e.Success {
2024-01-06 19:47:16 +08:00
return e.InternalError, "{\"Message\": \"storage error\"}"
}
config, status := h.runnerService.NewProblem(p.ProblemVersionID, url, true)
if status != e.Success {
2024-01-06 19:47:16 +08:00
return e.InternalError, "{\"Message\": \"build error: " + status.String() + "\"}"
}
for i := range config.Languages {
2023-07-16 16:27:12 +08:00
// do not store in db
config.Languages[i].Type = ""
config.Languages[i].Script = ""
config.Languages[i].Cmp = ""
}
b, _ := json.Marshal(config)
return e.Success, string(b)
}()
h.taskService.ProblemUpdate(&model.ProblemUpdatePayload{
Status: status,
ProblemVersionID: p.ProblemVersionID,
Context: ctx,
})
return nil
}