2022-10-22 17:38:39 +08:00
|
|
|
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"
|
2022-10-22 17:38:39 +08:00
|
|
|
"github.com/hibiken/asynq"
|
|
|
|
"go.uber.org/zap"
|
2022-10-23 17:29:35 +08:00
|
|
|
"time"
|
2022-10-22 17:38:39 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
2022-10-23 17:29:35 +08:00
|
|
|
status, ctx := func() (e.Status, string) {
|
|
|
|
url, status := h.storageService.Get(p.StorageKey, time.Second*60*5)
|
|
|
|
if status != e.Success {
|
|
|
|
return e.InternalError, "{}"
|
|
|
|
}
|
|
|
|
|
|
|
|
config, status := h.runnerService.NewProblem(p.ProblemVersionID, url, true)
|
|
|
|
if status != e.Success {
|
|
|
|
return e.InternalError, "{}"
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range config.Languages {
|
2023-07-16 16:27:12 +08:00
|
|
|
// do not store in db
|
2022-10-23 17:29:35 +08:00
|
|
|
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,
|
|
|
|
})
|
2022-10-22 17:38:39 +08:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|