From 68d7fdf646107ab690d458098d6de0d312887430 Mon Sep 17 00:00:00 2001 From: liuzx Date: Mon, 15 Nov 2021 15:53:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=97=B6=E9=97=B4=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/api/v1/repo/modelarts.go | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/routers/api/v1/repo/modelarts.go b/routers/api/v1/repo/modelarts.go index 052760041..91f88d24d 100755 --- a/routers/api/v1/repo/modelarts.go +++ b/routers/api/v1/repo/modelarts.go @@ -102,6 +102,14 @@ func GetModelArtsTrainJobVersion(ctx *context.APIContext) { job.Status = modelarts.TransTrainJobStatus(result.IntStatus) job.Duration = result.Duration job.TrainJobDuration = result.TrainJobDuration + + if result.Duration != 0 { + job.TrainJobDuration = addZero(result.Duration/3600000) + ":" + addZero(result.Duration%3600000/60000) + ":" + addZero(result.Duration%60000/1000) + + } else { + job.TrainJobDuration = "00:00:00" + } + err = models.UpdateJob(job) if err != nil { log.Error("UpdateJob failed:", err) @@ -110,11 +118,20 @@ func GetModelArtsTrainJobVersion(ctx *context.APIContext) { ctx.JSON(http.StatusOK, map[string]interface{}{ "JobID": jobID, "JobStatus": job.Status, - "JobDuration": job.Duration, + "JobDuration": job.TrainJobDuration, }) } +func addZero(t int64) (m string) { + if t < 10 { + m = "0" + strconv.FormatInt(t, 10) + return m + } else { + return strconv.FormatInt(t, 10) + } +} + func TrainJobGetLog(ctx *context.APIContext) { var ( err error @@ -125,6 +142,11 @@ func TrainJobGetLog(ctx *context.APIContext) { // var logFileName = ctx.Query("file_name") var baseLine = ctx.Query("base_line") var order = ctx.Query("order") + var lines = ctx.Query("lines") + lines_int, err := strconv.Atoi(lines) + if err != nil { + log.Error("change lines(%d) string to int failed", lines_int) + } if order != modelarts.OrderDesc && order != modelarts.OrderAsc { log.Error("order(%s) check failed", order) @@ -143,7 +165,7 @@ func TrainJobGetLog(ctx *context.APIContext) { // return // } - resultLogFile, result, err := trainJobGetLogContent(jobID, versionName, baseLine, order) + resultLogFile, result, err := trainJobGetLogContent(jobID, versionName, baseLine, order, lines_int) if err != nil { log.Error("trainJobGetLog(%s) failed:%v", jobID, err.Error()) // ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobShow, nil) @@ -170,7 +192,7 @@ func TrainJobGetLog(ctx *context.APIContext) { }) } -func trainJobGetLogContent(jobID string, versionName string, baseLine string, order string) (*models.GetTrainJobLogFileNamesResult, *models.GetTrainJobLogResult, error) { +func trainJobGetLogContent(jobID string, versionName string, baseLine string, order string, lines int) (*models.GetTrainJobLogFileNamesResult, *models.GetTrainJobLogResult, error) { task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName) if err != nil { log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error()) @@ -183,7 +205,7 @@ func trainJobGetLogContent(jobID string, versionName string, baseLine string, or return nil, nil, err } - result, err := modelarts.GetTrainJobLog(jobID, strconv.FormatInt(task.VersionID, 10), baseLine, resultLogFile.LogFileList[0], order, modelarts.Lines) + result, err := modelarts.GetTrainJobLog(jobID, strconv.FormatInt(task.VersionID, 10), baseLine, resultLogFile.LogFileList[0], order, lines) if err != nil { log.Error("GetTrainJobLog(%s) failed:%v", jobID, err.Error()) return nil, nil, err