From 04fffc69db4021a5681d4f40d11220c3d4dbe121 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 11 Oct 2022 14:12:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/aisafety.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/routers/repo/aisafety.go b/routers/repo/aisafety.go index 4708fbc24..a57abe3fa 100644 --- a/routers/repo/aisafety.go +++ b/routers/repo/aisafety.go @@ -296,6 +296,23 @@ func queryTaskStatusFromCloudbrainTwo(job *models.Cloudbrain) { } +func updateCloudBrainOneJobTime(task *models.Cloudbrain) { + if task.TrainJobDuration == "" { + if task.Duration == 0 { + var duration int64 + if task.Status == string(models.JobWaiting) { + duration = 0 + } else if task.Status == string(models.JobRunning) { + duration = time.Now().Unix() - int64(task.CreatedUnix) + } else { + duration = int64(task.UpdatedUnix) - int64(task.CreatedUnix) + } + task.Duration = duration + } + task.TrainJobDuration = models.ConvertDurationToStr(task.Duration) + } +} + func queryTaskStatusFromCloudbrain(job *models.Cloudbrain) { log.Info("The task not finished,name=" + job.DisplayJobName) @@ -312,6 +329,7 @@ func queryTaskStatusFromCloudbrain(job *models.Cloudbrain) { taskRes, _ := models.ConvertToTaskPod(taskRoles[cloudbrain.SubTaskName].(map[string]interface{})) job.Status = taskRes.TaskStatuses[0].State } + updateCloudBrainOneJobTime(job) log.Info("cloud brain one job status=" + job.Status) if result.JobStatus.State != string(models.JobSucceeded) { err = models.UpdateJob(job)