提交任务list时存储yamlString

Signed-off-by: devad <cossjie@foxmail.com>
This commit is contained in:
devad 2023-12-07 15:48:26 +08:00
parent eb90e99d47
commit cad9cccd41
3 changed files with 16 additions and 1 deletions

View File

@ -2,10 +2,12 @@ package core
import (
"context"
"github.com/ghodss/yaml"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/pkg/response"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/constants"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
"k8s.io/apimachinery/pkg/util/json"
"strings"
"time"
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
@ -29,12 +31,23 @@ func NewCommitTaskLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Commit
}
func (l *CommitTaskLogic) CommitTask(req *types.CommitTaskReq) error {
//req.YamlList转换为json
var yamlStr []string
for _, s := range req.YamlList {
j2, err := yaml.YAMLToJSON([]byte(s))
if err != nil {
logx.Errorf("Failed to convert yaml to JSON, err: %v", err)
return err
}
yamlStr = append(yamlStr, string(j2))
}
result := strings.Join(yamlStr, ",")
taskModel := models.Task{
Status: constants.Saved,
Name: req.Name,
CommitTime: time.Now(),
NsID: req.NsID,
YamlString: "[" + result + "]",
}
// 保存任务数据到数据库
tx := l.svcCtx.DbEngin.Create(&taskModel)

1
go.mod
View File

@ -9,6 +9,7 @@ require (
github.com/aws/aws-sdk-go v1.47.5
github.com/bwmarrin/snowflake v0.3.0
github.com/docker/docker v24.0.7+incompatible
github.com/ghodss/yaml v1.0.0
github.com/go-redis/redis/v8 v8.11.5
github.com/go-resty/resty/v2 v2.10.0
github.com/go-sql-driver/mysql v1.7.1

1
go.sum
View File

@ -532,6 +532,7 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/fullstorydev/grpcurl v1.8.7/go.mod h1:pVtM4qe3CMoLaIzYS8uvTuDj2jVYmXqMUkZeijnXp/E=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=