2022-10-23 17:29:35 +08:00
|
|
|
package consumer
|
|
|
|
|
|
|
|
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-23 17:29:35 +08:00
|
|
|
"github.com/hibiken/asynq"
|
|
|
|
"github.com/jackc/pgtype"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (h *handler) ProblemUpdate(_ context.Context, t *asynq.Task) error {
|
|
|
|
p := new(model.ProblemUpdatePayload)
|
|
|
|
if err := json.Unmarshal(t.Payload(), &p); err != nil {
|
|
|
|
return fmt.Errorf("json.Unmarshal failed: %v: %w", err, asynq.SkipRetry)
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.Status != e.Success {
|
|
|
|
h.log.Warn("RunnerError", zap.Any("payload", p))
|
|
|
|
}
|
|
|
|
|
|
|
|
status := h.problemService.UpdateVersion(
|
|
|
|
p.ProblemVersionID,
|
|
|
|
map[string]interface{}{
|
|
|
|
"Context": pgtype.JSON{
|
|
|
|
Bytes: []byte(p.Context),
|
|
|
|
Status: pgtype.Present,
|
|
|
|
},
|
2024-01-06 19:47:16 +08:00
|
|
|
"IsEnabled": p.Status == e.Success,
|
2022-10-23 17:29:35 +08:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
if status != e.Success {
|
|
|
|
return fmt.Errorf(status.String())
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|