89 lines
3.1 KiB
Go
89 lines
3.1 KiB
Go
package model
|
|
|
|
import (
|
|
"hpds_control_center/internal/proto"
|
|
"time"
|
|
)
|
|
|
|
type Task struct {
|
|
TaskId int64 `xorm:"not null pk autoincr INT(11)" json:"taskId"`
|
|
ModelId int64 `xorm:"INT(11) index" json:"modelId"`
|
|
NodeId int64 `xorm:"INT(11) index" json:"nodeId"`
|
|
TaskName string `xorm:"VARCHAR(200)" json:"taskName"`
|
|
TaskDesc string `xorm:"VARCHAR(500)" json:"taskDesc"`
|
|
DatasetArr string `xorm:"TEXT" json:"datasetArr"`
|
|
ResultStorage string `xorm:"TEXT" json:"resultStorage"`
|
|
AppointmentTime string `xorm:"VARCHAR(30)" json:"appointmentTime"`
|
|
StartTime int64 `xorm:"BIGINT" json:"startTime"`
|
|
FinishTime int64 `xorm:"BIGINT" json:"finishTime"`
|
|
TotalCount int64 `xorm:"INT" json:"totalCount"`
|
|
FailingCount int64 `xorm:"INT" json:"failingCount"`
|
|
CompletedCount int64 `xorm:"INT" json:"completedCount"`
|
|
UnfinishedCount int64 `xorm:"INT" json:"unfinishedCount"`
|
|
Status int `xorm:"not null SMALLINT default 0" json:"status"` // 1:等待执行; 2:执行中; 3:执行完成; 4:任务分配失败; 5:任务执行失败
|
|
CreateAt int64 `xorm:"created" json:"createAt"`
|
|
UpdateAt int64 `xorm:"updated" json:"updateAt"`
|
|
}
|
|
|
|
func UpdateTaskExecuteNode(id, nodeId int64) {
|
|
item := new(Task)
|
|
item.TaskId = id
|
|
item.NodeId = nodeId
|
|
_, _ = DB.ID(id).Cols("node_id").Update(item)
|
|
}
|
|
|
|
func UpdateTaskProgress(taskProgress *proto.TaskLogProgress) {
|
|
task := new(Task)
|
|
h, err := DB.ID(taskProgress.TaskId).Get(task)
|
|
if err != nil || !h {
|
|
return
|
|
}
|
|
if taskProgress.CompletedCount > task.CompletedCount {
|
|
task.CompletedCount = taskProgress.CompletedCount
|
|
}
|
|
if taskProgress.FailingCount > task.FailingCount {
|
|
task.FailingCount = taskProgress.FailingCount
|
|
}
|
|
if taskProgress.TotalCount != task.TotalCount && taskProgress.TotalCount > 0 {
|
|
task.TotalCount = taskProgress.TotalCount
|
|
}
|
|
if taskProgress.UnfinishedCount != task.UnfinishedCount && taskProgress.UnfinishedCount >= 0 {
|
|
task.UnfinishedCount = taskProgress.UnfinishedCount
|
|
}
|
|
if task.CompletedCount+task.FailingCount >= task.TotalCount {
|
|
task.Status = 3
|
|
} else {
|
|
task.Status = 2
|
|
}
|
|
task.UpdateAt = time.Now().Unix()
|
|
_, err = DB.ID(taskProgress.TaskId).Cols("completed_count", "failing_count", "total_count", "unfinished_count", "update_at").Update(task)
|
|
if err != nil {
|
|
return
|
|
}
|
|
}
|
|
|
|
func UpdateTaskProgressByLog(res *TaskResult, isFailing bool) (int, int) {
|
|
item := new(Task)
|
|
h, err := DB.ID(res.TaskId).Get(item)
|
|
if err != nil || !h {
|
|
return 0, 0
|
|
}
|
|
if isFailing {
|
|
item.FailingCount += 1
|
|
} else {
|
|
item.CompletedCount += 1
|
|
}
|
|
item.UnfinishedCount -= 1
|
|
if item.CompletedCount+item.FailingCount >= item.TotalCount {
|
|
item.FinishTime = time.Now().Unix()
|
|
item.UnfinishedCount = 0
|
|
item.Status = 3
|
|
}
|
|
item.UpdateAt = time.Now().Unix()
|
|
_, _ = DB.ID(res.TaskId).Cols("completed_count", "failing_count", "total_count", "unfinished_count", "update_at", "finish_time", "status").Update(item)
|
|
if item.TotalCount > 0 {
|
|
return int(item.CompletedCount), int(item.UnfinishedCount)
|
|
}
|
|
return int(item.CompletedCount), int(item.UnfinishedCount)
|
|
}
|