From 762b3b1c174786672bbcb511026b237e350a200e Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Mon, 19 Sep 2022 17:02:55 +0800 Subject: [PATCH] #1249 update point when multi node --- models/cloudbrain_spec.go | 10 +++++++--- routers/repo/modelarts.go | 2 +- services/reward/cloudbrain_deduct.go | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/models/cloudbrain_spec.go b/models/cloudbrain_spec.go index a14e3f886..c32e4b0fd 100644 --- a/models/cloudbrain_spec.go +++ b/models/cloudbrain_spec.go @@ -123,10 +123,14 @@ func GetResourceSpecMapByCloudbrainIDs(ids []int64) (map[int64]*Specification, e return r, nil } -func GetCloudbrainTaskUnitPrice(cloudbrainId int64) (int, error) { - s, err := GetCloudbrainSpecByID(cloudbrainId) +func GetCloudbrainTaskUnitPrice(task Cloudbrain) (int, error) { + s, err := GetCloudbrainSpecByID(task.ID) if err != nil { return 0, err } - return s.UnitPrice, nil + var n = 1 + if task.WorkServerNumber > 1 { + n = task.WorkServerNumber + } + return s.UnitPrice * n, nil } diff --git a/routers/repo/modelarts.go b/routers/repo/modelarts.go index 4f3341e6f..19b316a3b 100755 --- a/routers/repo/modelarts.go +++ b/routers/repo/modelarts.go @@ -1216,7 +1216,7 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) ctx.RenderWithErr("Resource specification not available", tplModelArtsTrainJobNew, &form) return } - if !account.IsPointBalanceEnough(ctx.User.ID, spec.UnitPrice) { + if !account.IsPointBalanceEnough(ctx.User.ID, spec.UnitPrice*form.WorkServerNumber) { log.Error("point balance is not enough,userId=%d specId=%d", ctx.User.ID, spec.ID) cloudBrainNewDataPrepare(ctx) ctx.RenderWithErr(ctx.Tr("points.insufficient_points_balance"), tplModelArtsTrainJobNew, &form) diff --git a/services/reward/cloudbrain_deduct.go b/services/reward/cloudbrain_deduct.go index f60c50aa1..826b79bdc 100644 --- a/services/reward/cloudbrain_deduct.go +++ b/services/reward/cloudbrain_deduct.go @@ -29,7 +29,7 @@ func StartAndGetCloudBrainPointDeductTask(task models.Cloudbrain) (*models.Rewar return nil, nil } - unitPrice, err := models.GetCloudbrainTaskUnitPrice(task.ID) + unitPrice, err := models.GetCloudbrainTaskUnitPrice(task) if err != nil { return nil, err }