fix status bugs
Former-commit-id: 547178d1d6f7af5c8b0745ad04885402a1da68b0
This commit is contained in:
parent
a779216f68
commit
c4d4e74d33
|
@ -4,6 +4,8 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
|
||||||
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/models"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
|
||||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/timeutils"
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/timeutils"
|
||||||
"time"
|
"time"
|
||||||
|
@ -49,6 +51,11 @@ func (l *PageListTaskLogic) PageListTask(req *types.PageTaskReq) (resp *types.Pa
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, result.NewDefaultError(err.Error())
|
return nil, result.NewDefaultError(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新智算任务状态
|
||||||
|
var ch = make(chan struct{})
|
||||||
|
go l.updateAitaskStatus(list, ch)
|
||||||
|
|
||||||
for _, model := range list {
|
for _, model := range list {
|
||||||
if model.StartTime != "" && model.EndTime == "" {
|
if model.StartTime != "" && model.EndTime == "" {
|
||||||
startTime := timeutils.TimeStringToGoTime(model.StartTime)
|
startTime := timeutils.TimeStringToGoTime(model.StartTime)
|
||||||
|
@ -65,5 +72,64 @@ func (l *PageListTaskLogic) PageListTask(req *types.PageTaskReq) (resp *types.Pa
|
||||||
resp.PageNum = req.PageNum
|
resp.PageNum = req.PageNum
|
||||||
resp.Total = total
|
resp.Total = total
|
||||||
|
|
||||||
return resp, nil
|
select {
|
||||||
|
case _ = <-ch:
|
||||||
|
return resp, nil
|
||||||
|
case <-time.After(1 * time.Second):
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *PageListTaskLogic) updateAitaskStatus(tasks []*types.TaskModel, ch chan<- struct{}) {
|
||||||
|
for _, task := range tasks {
|
||||||
|
if task.AdapterTypeDict != 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if task.Status == constants.Succeeded {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
var aiTask []*models.TaskAi
|
||||||
|
tx := l.svcCtx.DbEngin.Raw("select * from task_ai where `task_id` = ? ", task.Id).Scan(&aiTask)
|
||||||
|
if tx.Error != nil {
|
||||||
|
logx.Errorf(tx.Error.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
start, _ := time.ParseInLocation(constants.Layout, aiTask[0].StartTime, time.Local)
|
||||||
|
end, _ := time.ParseInLocation(constants.Layout, aiTask[0].EndTime, time.Local)
|
||||||
|
var status = constants.Succeeded
|
||||||
|
for _, a := range aiTask {
|
||||||
|
s, _ := time.ParseInLocation(constants.Layout, a.StartTime, time.Local)
|
||||||
|
e, _ := time.ParseInLocation(constants.Layout, a.EndTime, time.Local)
|
||||||
|
|
||||||
|
if s.Before(start) {
|
||||||
|
start = s
|
||||||
|
}
|
||||||
|
|
||||||
|
if e.After(end) {
|
||||||
|
end = e
|
||||||
|
}
|
||||||
|
|
||||||
|
if a.Status == constants.Failed {
|
||||||
|
status = a.Status
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if a.Status == constants.Running {
|
||||||
|
status = a.Status
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task.Status = status
|
||||||
|
task.StartTime = start.Format(constants.Layout)
|
||||||
|
task.EndTime = end.Format(constants.Layout)
|
||||||
|
|
||||||
|
tx = l.svcCtx.DbEngin.Table("task").Updates(task)
|
||||||
|
if tx.Error != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ch <- struct{}{}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue