diff --git a/api/desc/core/pcm-core.api b/api/desc/core/pcm-core.api index 973f5944..da7df371 100644 --- a/api/desc/core/pcm-core.api +++ b/api/desc/core/pcm-core.api @@ -1174,7 +1174,7 @@ type TaskStatusResp { Succeeded int `json:"Succeeded"` Failed int `json:"Failed"` Running int `json:"Running"` - Pause int `json:"Pause"` + Saved int `json:"Saved"` } type TaskDetailsResp { @@ -1182,7 +1182,7 @@ type TaskDetailsResp { description string `json:"description"` StartTime string `json:"startTime"` EndTime string `json:"endTime"` - Strategy int64 `json:"strategy,string"` - SynergyStatus int64 `json:"synergyStatus,string"` + Strategy int64 `json:"strategy"` + SynergyStatus int64 `json:"synergyStatus"` ClusterInfos []*ClusterInfo `json:"clusterInfos"` } \ No newline at end of file diff --git a/api/internal/logic/core/pushtaskinfologic.go b/api/internal/logic/core/pushtaskinfologic.go index df1635d0..5d86bca2 100644 --- a/api/internal/logic/core/pushtaskinfologic.go +++ b/api/internal/logic/core/pushtaskinfologic.go @@ -77,7 +77,6 @@ func syncTask(gorm *gorm.DB, taskId int64) { statusArray := strings.Split(allStatus, ",") if len(removeRepeatedElement(statusArray)) == 1 { updateTask(gorm, taskId, statusArray[0]) - } // 子任务包含失败状态 主任务则失败 if strings.Contains(allStatus, constants.Failed) { @@ -85,26 +84,20 @@ func syncTask(gorm *gorm.DB, taskId int64) { } if strings.Contains(allStatus, constants.Running) { - updateTaskRunning(gorm, taskId, constants.Running) + updateTask(gorm, taskId, constants.Running) } } func updateTask(gorm *gorm.DB, taskId int64, status string) { + now := time.Now() var task models.Task gorm.Where("id = ? ", taskId).Find(&task) if task.Status != status { task.Status = status - gorm.Updates(&task) - } -} - -func updateTaskRunning(gorm *gorm.DB, taskId int64, status string) { - var task models.Task - gorm.Where("id = ? ", taskId).Find(&task) - if task.Status != status { - task.Status = status - task.StartTime = time.Now().Format("2006-01-02 15:04:05") + if status == constants.Running { + task.StartTime = &now + } gorm.Updates(&task) } } diff --git a/api/internal/logic/core/taskdetailslogic.go b/api/internal/logic/core/taskdetailslogic.go index da4acde5..fb1a3ecd 100644 --- a/api/internal/logic/core/taskdetailslogic.go +++ b/api/internal/logic/core/taskdetailslogic.go @@ -3,11 +3,11 @@ package core import ( "context" "github.com/pkg/errors" - "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" - "gorm.io/gorm" - "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc" "gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models" + "gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils" + "gorm.io/gorm" "github.com/zeromicro/go-zero/core/logx" ) @@ -27,8 +27,8 @@ func NewTaskDetailsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TaskD } func (l *TaskDetailsLogic) TaskDetails(req *types.FId) (resp *types.TaskDetailsResp, err error) { - - var task models.Task + resp = &types.TaskDetailsResp{} + task := &models.Task{} if errors.Is(l.svcCtx.DbEngin.Where("id", req.Id).First(&task).Error, gorm.ErrRecordNotFound) { return nil, errors.New("记录不存在") } @@ -48,14 +48,7 @@ func (l *TaskDetailsLogic) TaskDetails(req *types.FId) (resp *types.TaskDetailsR if err != nil { return resp, err } - resp = &types.TaskDetailsResp{ - Name: task.Name, - Description: task.Description, - StartTime: task.StartTime, - EndTime: task.EndTime, - Strategy: task.Strategy, - SynergyStatus: task.SynergyStatus, - ClusterInfos: cList, - } + utils.Convert(&task, &resp) + resp.ClusterInfos = cList return } diff --git a/api/internal/logic/core/tasklistlogic.go b/api/internal/logic/core/tasklistlogic.go index 30818f24..e56be650 100644 --- a/api/internal/logic/core/tasklistlogic.go +++ b/api/internal/logic/core/tasklistlogic.go @@ -93,13 +93,12 @@ func (l *TaskListLogic) TaskList(req *types.TaskListReq) (resp *types.TaskListRe pStatus = "Normal" } } - resp.Tasks = append(resp.Tasks, types.Task{ Id: task.Id, Name: task.Name, Status: task.Status, - StartTime: task.StartTime, - EndTime: task.EndTime, + StartTime: task.StartTime.Format("2006-01-02 15:04:05"), + EndTime: task.EndTime.Format("2006-01-02 15:04:05"), ParticipantId: pInfo.Id, ParticipantName: pInfo.Name, ParticipantStatus: pStatus, diff --git a/api/internal/types/types.go b/api/internal/types/types.go index 806d8762..cc217112 100644 --- a/api/internal/types/types.go +++ b/api/internal/types/types.go @@ -1078,7 +1078,7 @@ type TaskStatusResp struct { Succeeded int `json:"Succeeded"` Failed int `json:"Failed"` Running int `json:"Running"` - Pause int `json:"Pause"` + Saved int `json:"Saved"` } type TaskDetailsResp struct { @@ -1086,8 +1086,8 @@ type TaskDetailsResp struct { Description string `json:"description"` StartTime string `json:"startTime"` EndTime string `json:"endTime"` - Strategy int64 `json:"strategy,string"` - SynergyStatus int64 `json:"synergyStatus,string"` + Strategy int64 `json:"strategy"` + SynergyStatus int64 `json:"synergyStatus"` ClusterInfos []*ClusterInfo `json:"clusterInfos"` } diff --git a/pkg/models/taskmodel_gen.go b/pkg/models/taskmodel_gen.go index b8ee8603..5dae890c 100644 --- a/pkg/models/taskmodel_gen.go +++ b/pkg/models/taskmodel_gen.go @@ -42,8 +42,8 @@ type ( Strategy int64 `db:"strategy"` // 策略 SynergyStatus int64 `db:"synergy_status"` // 协同状态(0-未协同、1-已协同) CommitTime time.Time `db:"commit_time"` // 提交时间 - StartTime string `db:"start_time"` // 开始时间 - EndTime string `db:"end_time"` // 结束运行时间 + StartTime *time.Time `db:"start_time"` // 开始时间 + EndTime *time.Time `db:"end_time"` // 结束运行时间 RunningTime int64 `db:"running_time"` // 已运行时间(单位秒) YamlString string `db:"yaml_string"` Result string `db:"result"` // 作业结果