woj-server/internal/service/task/submit.go
Paul Pan d42ee0ce54 feat: a big update
1. merge woj-runner scripts into woj-server
2. add woj-runner app
3. refactor submission status problem ...
4. jwt middleware update

Co-authored-by: cxy004 <cxy004@qq.com>
Co-authored-by: wzt <w.zhongtao@qq.com>
2022-10-22 17:38:39 +08:00

56 lines
1.4 KiB
Go

package task
import (
"encoding/json"
"github.com/WHUPRJ/woj-server/internal/e"
"github.com/WHUPRJ/woj-server/internal/model"
"github.com/WHUPRJ/woj-server/internal/service/runner"
"go.uber.org/zap"
)
func (s *service) SubmitJudge(pvid uint, storageKey string, submission model.Submission) (string, e.Status) {
payload, err := json.Marshal(
model.SubmitJudgePayload{
ProblemVersionId: pvid,
StorageKey: storageKey,
Submission: submission,
})
if err != nil {
s.log.Warn("json marshal error", zap.Error(err), zap.Any("Submission", submission))
return "", e.InternalError
}
info, status := s.submit(model.TypeSubmitJudge, payload, model.QueueRunner)
return info.ID, status
}
func (s *service) SubmitUpdate(status e.Status, sid uint, point int32, ctx runner.JudgeStatus) (string, e.Status) {
ctxText, err := json.Marshal(ctx)
if err != nil {
s.log.Warn("json marshal error",
zap.Error(err),
zap.Any("ctx", ctx))
return "", e.InternalError
}
payload, err := json.Marshal(model.SubmitUpdatePayload{
Status: status,
Sid: sid,
Point: point,
Context: string(ctxText),
})
if err != nil {
s.log.Warn("json marshal error",
zap.Error(err),
zap.Any("Status", status),
zap.Int32("Point", point),
zap.Any("Context", ctx))
return "", e.InternalError
}
info, status := s.submit(model.TypeSubmitUpdate, payload, model.QueueServer)
return info.ID, status
}