From 065d20cc0a014e509ca20ed89d142f0a1670f865 Mon Sep 17 00:00:00 2001 From: Lijunmao Date: Thu, 25 Aug 2022 10:37:14 +0800 Subject: [PATCH] add --- server/base-server/internal/service/develop/task.go | 10 +++++++--- server/base-server/internal/service/trainjob/task.go | 6 ++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/server/base-server/internal/service/develop/task.go b/server/base-server/internal/service/develop/task.go index 2989daeb..0358c2df 100644 --- a/server/base-server/internal/service/develop/task.go +++ b/server/base-server/internal/service/develop/task.go @@ -156,7 +156,11 @@ func (s *developService) startNotebookTask() { var payEndAt int64 var payStatus api.BillingPayRecordStatus if utils.IsCompletedState(j.Status) { - payEndAt = j.StoppedAt.Unix() + if j.StoppedAt == nil { + payEndAt = time.Now().Unix() + } else { + payEndAt = j.StoppedAt.Unix() + } payStatus = api.BillingPayRecordStatus_BPRS_PAY_COMPLETED } else { payEndAt = time.Now().Unix() @@ -224,7 +228,7 @@ func (s *developService) startNotebookTask() { state := utils.MapPhaseToState(typeJob.JobPhase(job.Status.State.Phase)) - if utils.IsCompletedState(nbJob.Status) || strings.EqualFold(nbJob.Status, state) { + if utils.IsCompletedState(nbJob.Status) { continue } @@ -259,7 +263,7 @@ func (s *developService) startNotebookTask() { NotebookId: nb.Id, } - if strings.EqualFold(state, constant.RUNNING) { + if strings.EqualFold(state, constant.RUNNING) && strings.EqualFold(nbJob.Status, constant.PENDING) { nbJobUp.StartedAt = &now record.Type = commapi.NotebookEventRecordType_RUN } else if utils.IsCompletedState(state) { diff --git a/server/base-server/internal/service/trainjob/task.go b/server/base-server/internal/service/trainjob/task.go index 54f27a15..70cfd45f 100644 --- a/server/base-server/internal/service/trainjob/task.go +++ b/server/base-server/internal/service/trainjob/task.go @@ -256,10 +256,8 @@ func (s *trainJobService) trainJobUpdateStaus(ctx context.Context) { s.log.Warn(context.TODO(), "GetTrainJob err when onJobUpdate:"+job.Name, err) continue } - state := utils.MapPhaseToState(typeJob.JobPhase(job.Status.State.Phase)) - - if utils.IsCompletedState(trainJob.Status) || strings.EqualFold(trainJob.Status, state) { + if utils.IsCompletedState(trainJob.Status) { continue } @@ -269,7 +267,7 @@ func (s *trainJobService) trainJobUpdateStaus(ctx context.Context) { } now := time.Now() - if strings.EqualFold(state, constant.RUNNING) { + if strings.EqualFold(state, constant.RUNNING) && strings.EqualFold(trainJob.Status, constant.PENDING) { update.StartedAt = &now } else if utils.IsCompletedState(state) { update.CompletedAt = &now -- 2.34.1