fix bug
Signed-off-by: jagger <cossjie@foxmail.com> Former-commit-id: bf0f7835384dbd6813fff0006c218209818a7379
This commit is contained in:
parent
3f4d8924d8
commit
375de5c4b2
|
@ -86,7 +86,8 @@ func (l *PageListTaskLogic) PageListTask(req *types.PageTaskReq) (resp *types.Pa
|
|||
}
|
||||
|
||||
func (l *PageListTaskLogic) updateTaskStatus(tasklist []*types.TaskModel, ch chan<- struct{}) {
|
||||
list := tasklist
|
||||
var list []*types.TaskModel
|
||||
copy(list, tasklist)
|
||||
for i := len(list) - 1; i >= 0; i-- {
|
||||
if list[i].AdapterTypeDict != 1 || list[i].Status == constants.Succeeded || list[i].Status == constants.Failed {
|
||||
list = append(list[:i], list[i+1:]...)
|
||||
|
@ -99,7 +100,7 @@ func (l *PageListTaskLogic) updateTaskStatus(tasklist []*types.TaskModel, ch cha
|
|||
}
|
||||
|
||||
task := list[0]
|
||||
for i, _ := range list {
|
||||
for i := range list {
|
||||
earliest, _ := time.Parse(constants.Layout, task.UpdatedTime)
|
||||
latest, _ := time.Parse(constants.Layout, list[i].UpdatedTime)
|
||||
if latest.Before(earliest) {
|
||||
|
@ -208,7 +209,8 @@ func (l *PageListTaskLogic) updateTaskStatus(tasklist []*types.TaskModel, ch cha
|
|||
}
|
||||
|
||||
func (l *PageListTaskLogic) updateAiTaskStatus(tasklist []*types.TaskModel, ch chan<- struct{}) {
|
||||
list := tasklist
|
||||
var list []*types.TaskModel
|
||||
copy(list, tasklist)
|
||||
for i := len(list) - 1; i >= 0; i-- {
|
||||
if list[i].AdapterTypeDict != 1 || list[i].Status == constants.Succeeded || list[i].Status == constants.Failed {
|
||||
list = append(list[:i], list[i+1:]...)
|
||||
|
@ -221,7 +223,7 @@ func (l *PageListTaskLogic) updateAiTaskStatus(tasklist []*types.TaskModel, ch c
|
|||
}
|
||||
|
||||
task := list[0]
|
||||
for i, _ := range list {
|
||||
for i := range list {
|
||||
earliest, _ := time.Parse(constants.Layout, task.UpdatedTime)
|
||||
latest, _ := time.Parse(constants.Layout, list[i].UpdatedTime)
|
||||
if latest.Before(earliest) {
|
||||
|
|
|
@ -21,6 +21,7 @@ import (
|
|||
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/scheduler/service/collector"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/constants"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
|
||||
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils/timeutils"
|
||||
"gitlink.org.cn/JointCloud/pcm-modelarts/client/imagesservice"
|
||||
"gitlink.org.cn/JointCloud/pcm-modelarts/client/modelartsservice"
|
||||
"gitlink.org.cn/JointCloud/pcm-modelarts/modelarts"
|
||||
|
@ -243,14 +244,20 @@ func (m *ModelArtsLink) GetTrainingTask(ctx context.Context, taskId string) (*co
|
|||
|
||||
switch strings.ToLower(jobresp.Status.Phase) {
|
||||
case "completed":
|
||||
task.Start = time.Unix(int64(jobresp.Status.StartTime)/1000, 0).Format(constants.Layout)
|
||||
duration := jobresp.Status.Duration
|
||||
task.End = time.Unix(int64(jobresp.Status.StartTime)/1000+int64(duration/1000), 0).Format(constants.Layout)
|
||||
milliTimestamp := int64(jobresp.Status.StartTime)
|
||||
task.Start = timeutils.MillisecondsToUTCString(milliTimestamp, time.DateTime)
|
||||
duration := int64(jobresp.Status.Duration)
|
||||
task.End = timeutils.MillisecondsToAddDurationToUTCString(milliTimestamp, duration, time.DateTime)
|
||||
task.Status = constants.Completed
|
||||
case "failed":
|
||||
milliTimestamp := int64(jobresp.Status.StartTime)
|
||||
task.Start = timeutils.MillisecondsToUTCString(milliTimestamp, time.DateTime)
|
||||
duration := int64(jobresp.Status.Duration)
|
||||
task.End = timeutils.MillisecondsToAddDurationToUTCString(milliTimestamp, duration, time.DateTime)
|
||||
task.Status = constants.Failed
|
||||
case "running":
|
||||
task.Start = time.Unix(int64(jobresp.Status.StartTime)/1000, 0).Format(constants.Layout)
|
||||
milliTimestamp := int64(jobresp.Status.StartTime)
|
||||
task.Start = timeutils.MillisecondsToUTCString(milliTimestamp, time.DateTime)
|
||||
task.Status = constants.Running
|
||||
case "stopped":
|
||||
task.Status = constants.Stopped
|
||||
|
|
|
@ -77,3 +77,33 @@ func UnixTimeToString(ut int64) string {
|
|||
|
||||
return t.Format("2006-01-02 15:04:05")
|
||||
}
|
||||
|
||||
// MillisecondsToUTCString 将毫秒时间戳转换为UTC时间的字符串表示
|
||||
func MillisecondsToUTCString(milliseconds int64, layout string) string {
|
||||
// 将毫秒转换为秒
|
||||
timestamp := milliseconds / 1000
|
||||
// 创建time.Time对象
|
||||
timeObj := time.Unix(timestamp, (milliseconds%1000)*int64(time.Millisecond))
|
||||
// 使用RFC3339格式返回UTC时间字符串
|
||||
return timeObj.UTC().Format(layout)
|
||||
}
|
||||
|
||||
// SecondsToUTCString 将秒时间戳转换为UTC时间的字符串表示
|
||||
func SecondsToUTCString(seconds int64, layout string) string {
|
||||
// 创建time.Time对象
|
||||
timeObj := time.Unix(seconds, 0)
|
||||
// 使用RFC3339格式返回UTC时间字符串
|
||||
return timeObj.UTC().Format(layout)
|
||||
}
|
||||
|
||||
// MillisecondsToAddDurationToUTCString 将毫秒时间戳加上持续时间毫秒后转换为UTC时间的字符串表示
|
||||
func MillisecondsToAddDurationToUTCString(milliseconds int64, durationMilliseconds int64, layout string) string {
|
||||
// 将毫秒时间戳转换为秒
|
||||
timestamp := milliseconds / 1000
|
||||
// 创建time.Time对象
|
||||
timeObj := time.Unix(timestamp, (milliseconds%1000)*int64(time.Millisecond))
|
||||
// 添加持续时间
|
||||
duration := time.Duration(durationMilliseconds) * time.Millisecond
|
||||
// 返回加上持续时间后的UTC时间字符串
|
||||
return timeObj.Add(duration).UTC().Format(layout)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue