@@ -204,7 +204,7 @@ type CloudbrainShow struct { | |||
JobType string | |||
DisplayJobName string | |||
Duration string | |||
ResourceSpec *ResourceAndFlavor | |||
ResourceSpec *Specification | |||
ComputeResource string | |||
AiCenter string | |||
} | |||
@@ -226,7 +226,7 @@ func (task *Cloudbrain) ToShow() *CloudbrainShow { | |||
Type: task.Type, | |||
DisplayJobName: task.DisplayJobName, | |||
Duration: task.TrainJobDuration, | |||
ResourceSpec: GetCloudbrainResourceSpec(task.JobType, task.Type, task.ResourceSpecId, task.FlavorCode), | |||
ResourceSpec: task.Spec, | |||
ComputeResource: task.ComputeResource, | |||
} | |||
if task.Repo != nil { | |||
@@ -2292,133 +2292,6 @@ func GetCloudbrainByIds(ids []int64) ([]*Cloudbrain, error) { | |||
return cloudbrains, nil | |||
} | |||
var ( | |||
SpecsMapInitFlag = false | |||
CloudbrainDebugResourceSpecsMap map[int]*ResourceSpec | |||
CloudbrainTrainResourceSpecsMap map[int]*ResourceSpec | |||
CloudbrainBenchmarkResourceSpecsMap map[int]*ResourceSpec | |||
ModelArtsDebugResourceSpecsMap map[string]*FlavorInfo | |||
ModelArtsTrainResourceSpecsMap map[string]*FlavorInfo | |||
) | |||
type ModelArtsFlavor struct { | |||
Info []struct { | |||
Code string `json:"code"` | |||
Value string `json:"value"` | |||
UnitPrice int64 `json:"unitPrice"` | |||
} `json:"flavor"` | |||
} | |||
func InitResourceSpecMap() { | |||
if CloudbrainDebugResourceSpecsMap == nil || len(CloudbrainDebugResourceSpecsMap) == 0 { | |||
t := ResourceSpecs{} | |||
json.Unmarshal([]byte(setting.ResourceSpecs), &t) | |||
CloudbrainDebugResourceSpecsMap = make(map[int]*ResourceSpec, len(t.ResourceSpec)) | |||
for _, spec := range t.ResourceSpec { | |||
CloudbrainDebugResourceSpecsMap[spec.Id] = spec | |||
} | |||
} | |||
if CloudbrainTrainResourceSpecsMap == nil || len(CloudbrainTrainResourceSpecsMap) == 0 { | |||
t := ResourceSpecs{} | |||
json.Unmarshal([]byte(setting.TrainResourceSpecs), &t) | |||
CloudbrainTrainResourceSpecsMap = make(map[int]*ResourceSpec, len(t.ResourceSpec)) | |||
for _, spec := range t.ResourceSpec { | |||
CloudbrainTrainResourceSpecsMap[spec.Id] = spec | |||
} | |||
} | |||
if CloudbrainBenchmarkResourceSpecsMap == nil || len(CloudbrainBenchmarkResourceSpecsMap) == 0 { | |||
t := ResourceSpecs{} | |||
json.Unmarshal([]byte(setting.BenchmarkResourceSpecs), &t) | |||
CloudbrainBenchmarkResourceSpecsMap = make(map[int]*ResourceSpec, len(t.ResourceSpec)) | |||
for _, spec := range t.ResourceSpec { | |||
CloudbrainBenchmarkResourceSpecsMap[spec.Id] = spec | |||
} | |||
} | |||
if ModelArtsDebugResourceSpecsMap == nil || len(ModelArtsDebugResourceSpecsMap) == 0 { | |||
t := FlavorInfos{} | |||
json.Unmarshal([]byte(setting.FlavorInfos), &t) | |||
ModelArtsDebugResourceSpecsMap = make(map[string]*FlavorInfo, len(t.FlavorInfo)) | |||
for _, spec := range t.FlavorInfo { | |||
ModelArtsDebugResourceSpecsMap[spec.Value] = spec | |||
} | |||
} | |||
if ModelArtsTrainResourceSpecsMap == nil || len(ModelArtsTrainResourceSpecsMap) == 0 { | |||
t := ModelArtsFlavor{} | |||
json.Unmarshal([]byte(setting.TrainJobFLAVORINFOS), &t) | |||
ModelArtsTrainResourceSpecsMap = make(map[string]*FlavorInfo, len(t.Info)) | |||
for _, spec := range t.Info { | |||
f := &FlavorInfo{ | |||
Value: spec.Code, | |||
Desc: spec.Value, | |||
UnitPrice: spec.UnitPrice, | |||
} | |||
ModelArtsTrainResourceSpecsMap[spec.Value] = f | |||
} | |||
} | |||
SpecsMapInitFlag = true | |||
} | |||
type ResourceAndFlavor struct { | |||
ResourceSpec *ResourceSpec | |||
FlavorInfo *FlavorInfo | |||
} | |||
func NewResourceAndFlavor(resourceSpec *ResourceSpec, flavorInfo *FlavorInfo) *ResourceAndFlavor { | |||
return &ResourceAndFlavor{ | |||
ResourceSpec: resourceSpec, | |||
FlavorInfo: flavorInfo, | |||
} | |||
} | |||
func GetCloudbrainResourceSpec(jobType string, clusterType int, resourceSpecId int, flavorCode string) *ResourceAndFlavor { | |||
if !SpecsMapInitFlag { | |||
InitResourceSpecMap() | |||
} | |||
if clusterType == TypeCloudBrainOne { | |||
switch jobType { | |||
case string(JobTypeDebug): | |||
return NewResourceAndFlavor(CloudbrainDebugResourceSpecsMap[resourceSpecId], nil) | |||
case string(JobTypeTrain): | |||
return NewResourceAndFlavor(CloudbrainTrainResourceSpecsMap[resourceSpecId], nil) | |||
case string(JobTypeBenchmark): | |||
return NewResourceAndFlavor(CloudbrainBenchmarkResourceSpecsMap[resourceSpecId], nil) | |||
} | |||
} else if clusterType == TypeCloudBrainTwo { | |||
switch jobType { | |||
case string(JobTypeDebug): | |||
return NewResourceAndFlavor(nil, ModelArtsDebugResourceSpecsMap[flavorCode]) | |||
case string(JobTypeTrain): | |||
return NewResourceAndFlavor(nil, ModelArtsTrainResourceSpecsMap[flavorCode]) | |||
case string(JobTypeInference): | |||
return NewResourceAndFlavor(nil, ModelArtsTrainResourceSpecsMap[flavorCode]) | |||
} | |||
} | |||
return nil | |||
} | |||
func GetCloudbrainTaskUnitPrice(task Cloudbrain) int64 { | |||
spec := GetCloudbrainResourceSpec(task.JobType, task.Type, task.ResourceSpecId, task.FlavorCode) | |||
if spec == nil { | |||
return 0 | |||
} | |||
if task.Type == TypeCloudBrainOne { | |||
if spec.ResourceSpec == nil { | |||
return 0 | |||
} | |||
return spec.ResourceSpec.UnitPrice | |||
} else if task.Type == TypeCloudBrainTwo { | |||
if spec.FlavorInfo == nil { | |||
return 0 | |||
} | |||
return spec.FlavorInfo.UnitPrice | |||
} | |||
return 0 | |||
} | |||
type DatasetInfo struct { | |||
DataLocalPath string | |||
Name string | |||
@@ -107,3 +107,24 @@ func CountNoSpecHistoricTask() (int64, error) { | |||
} | |||
return n, nil | |||
} | |||
// GetResourceSpecMapByCloudbrainIDs | |||
func GetResourceSpecMapByCloudbrainIDs(ids []int64) (map[int64]*Specification, error) { | |||
specs := make([]*CloudbrainSpec, 0) | |||
if err := x.In("cloudbrain_id", ids).Find(&specs); err != nil { | |||
return nil, err | |||
} | |||
r := make(map[int64]*Specification, len(ids)) | |||
for _, s := range specs { | |||
r[s.CloudbrainID] = s.ConvertToSpecification() | |||
} | |||
return r, nil | |||
} | |||
func GetCloudbrainTaskUnitPrice(cloudbrainId int64) (int, error) { | |||
s, err := GetCloudbrainSpecByID(cloudbrainId) | |||
if err != nil { | |||
return 0, err | |||
} | |||
return s.UnitPrice, nil | |||
} |
@@ -167,16 +167,20 @@ func (l RewardRecordShowList) loadCloudbrain() error { | |||
if err != nil { | |||
return err | |||
} | |||
var ids []int64 | |||
var repoIds []int64 | |||
var taskIds []int64 | |||
for _, task := range cloudbrains { | |||
ids = append(ids, task.RepoID) | |||
repoIds = append(repoIds, task.RepoID) | |||
taskIds = append(taskIds, task.ID) | |||
} | |||
repositoryMap, err := GetRepositoriesMapByIDs(ids) | |||
repositoryMap, err := GetRepositoriesMapByIDs(repoIds) | |||
specMap, err := GetResourceSpecMapByCloudbrainIDs(taskIds) | |||
if err != nil { | |||
return err | |||
} | |||
for _, v := range cloudbrains { | |||
v.Repo = repositoryMap[v.RepoID] | |||
v.Spec = specMap[v.ID] | |||
cloudbrainMap[v.ID].Cloudbrain = v.ToShow() | |||
} | |||
@@ -51,7 +51,7 @@ type StartPeriodicTaskOpts struct { | |||
OperateType RewardOperateType | |||
Delay time.Duration | |||
Interval time.Duration | |||
UnitAmount int64 | |||
UnitAmount int | |||
RewardType RewardType | |||
StartTime time.Time | |||
} | |||
@@ -1,9 +1,9 @@ | |||
package authentication | |||
import ( | |||
"code.gitea.io/gitea/modules/auth/wechat" | |||
"code.gitea.io/gitea/modules/context" | |||
"code.gitea.io/gitea/modules/log" | |||
wechat "code.gitea.io/gitea/services/wechat" | |||
"encoding/xml" | |||
"io/ioutil" | |||
"time" | |||
@@ -2,8 +2,8 @@ package repo | |||
import ( | |||
"bufio" | |||
"code.gitea.io/gitea/services/reward/point/account" | |||
"code.gitea.io/gitea/services/cloudbrain/resource" | |||
"code.gitea.io/gitea/services/reward/point/account" | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
@@ -198,13 +198,6 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||
repo := ctx.Repo.Repository | |||
tpl := tplCloudBrainNew | |||
if !account.IsPointBalanceEnough(ctx.User.ID, jobType, models.TypeCloudBrainOne, resourceSpecId, "") { | |||
log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, jobType, resourceSpecId) | |||
cloudBrainNewDataPrepare(ctx) | |||
ctx.RenderWithErr(ctx.Tr("points.insufficient_points_balance"), tpl, &form) | |||
return | |||
} | |||
if jobType == string(models.JobTypeTrain) { | |||
tpl = tplCloudBrainTrainJobNew | |||
} | |||
@@ -310,6 +303,13 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { | |||
return | |||
} | |||
if !account.IsPointBalanceEnough(ctx.User.ID, spec.UnitPrice) { | |||
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"), tpl, &form) | |||
return | |||
} | |||
req := cloudbrain.GenerateCloudBrainTaskReq{ | |||
Ctx: ctx, | |||
DisplayJobName: displayJobName, | |||
@@ -556,13 +556,6 @@ func CloudBrainRestart(ctx *context.Context) { | |||
var status = string(models.JobWaiting) | |||
task := ctx.Cloudbrain | |||
for { | |||
if !account.IsPointBalanceEnough(ctx.User.ID, task.JobType, models.TypeCloudBrainOne, task.ResourceSpecId, "") { | |||
log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, task.JobType, task.ResourceSpecId) | |||
resultCode = "-1" | |||
errorMsg = ctx.Tr("points.insufficient_points_balance") | |||
break | |||
} | |||
if task.Status != string(models.JobStopped) && task.Status != string(models.JobSucceeded) && task.Status != string(models.JobFailed) { | |||
log.Error("the job(%s) is not stopped", task.JobName, ctx.Data["MsgID"]) | |||
resultCode = "-1" | |||
@@ -604,6 +597,13 @@ func CloudBrainRestart(ctx *context.Context) { | |||
} | |||
task.Spec = spec | |||
if !account.IsPointBalanceEnough(ctx.User.ID, spec.UnitPrice) { | |||
log.Error("point balance is not enough,userId=%d specId=%d", ctx.User.ID, spec.ID) | |||
resultCode = "-1" | |||
errorMsg = ctx.Tr("points.insufficient_points_balance") | |||
break | |||
} | |||
count, err := models.GetCloudbrainCountByUserID(ctx.User.ID, string(models.JobTypeDebug)) | |||
if err != nil { | |||
log.Error("GetCloudbrainCountByUserID failed:%v", err, ctx.Data["MsgID"]) | |||
@@ -2227,13 +2227,6 @@ func BenchMarkAlgorithmCreate(ctx *context.Context, form auth.CreateCloudBrainFo | |||
repo := ctx.Repo.Repository | |||
if !account.IsPointBalanceEnough(ctx.User.ID, string(models.JobTypeBenchmark), models.TypeCloudBrainOne, cloudbrain.BenchMarkResourceID, "") { | |||
log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, string(models.JobTypeBenchmark), resourceSpecId) | |||
cloudBrainNewDataPrepare(ctx) | |||
ctx.RenderWithErr(ctx.Tr("points.insufficient_points_balance"), tplCloudBrainBenchmarkNew, &form) | |||
return | |||
} | |||
tasks, err := models.GetCloudbrainsByDisplayJobName(repo.ID, string(models.JobTypeBenchmark), displayJobName) | |||
if err == nil { | |||
if len(tasks) != 0 { | |||
@@ -2275,6 +2268,12 @@ func BenchMarkAlgorithmCreate(ctx *context.Context, form auth.CreateCloudBrainFo | |||
ctx.RenderWithErr("Resource specification not available", tplCloudBrainBenchmarkNew, &form) | |||
return | |||
} | |||
if !account.IsPointBalanceEnough(ctx.User.ID, spec.UnitPrice) { | |||
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"), tplCloudBrainBenchmarkNew, &form) | |||
return | |||
} | |||
count, err := models.GetBenchmarkCountByUserID(ctx.User.ID) | |||
if err != nil { | |||
@@ -2407,13 +2406,6 @@ func ModelBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainForm) | |||
tpl := tplCloudBrainBenchmarkNew | |||
command := cloudbrain.GetCloudbrainDebugCommand() | |||
if !account.IsPointBalanceEnough(ctx.User.ID, jobType, models.TypeCloudBrainOne, resourceSpecId, "") { | |||
log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, jobType, resourceSpecId) | |||
cloudBrainNewDataPrepare(ctx) | |||
ctx.RenderWithErr(ctx.Tr("points.insufficient_points_balance"), tpl, &form) | |||
return | |||
} | |||
tasks, err := models.GetCloudbrainsByDisplayJobName(repo.ID, jobType, displayJobName) | |||
if err == nil { | |||
if len(tasks) != 0 { | |||
@@ -2499,6 +2491,13 @@ func ModelBenchmarkCreate(ctx *context.Context, form auth.CreateCloudBrainForm) | |||
ctx.RenderWithErr("Resource specification not available", tpl, &form) | |||
return | |||
} | |||
if !account.IsPointBalanceEnough(ctx.User.ID, spec.UnitPrice) { | |||
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"), tpl, &form) | |||
return | |||
} | |||
req := cloudbrain.GenerateCloudBrainTaskReq{ | |||
Ctx: ctx, | |||
DisplayJobName: displayJobName, | |||
@@ -2,8 +2,8 @@ package repo | |||
import ( | |||
"archive/zip" | |||
"code.gitea.io/gitea/services/reward/point/account" | |||
"code.gitea.io/gitea/services/cloudbrain/resource" | |||
"code.gitea.io/gitea/services/reward/point/account" | |||
"encoding/json" | |||
"errors" | |||
"io" | |||
@@ -214,12 +214,6 @@ func Notebook2Create(ctx *context.Context, form auth.CreateModelArtsNotebookForm | |||
imageId := form.ImageId | |||
repo := ctx.Repo.Repository | |||
if !account.IsPointBalanceEnough(ctx.User.ID, string(models.JobTypeDebug), models.TypeCloudBrainTwo, 0, flavor) { | |||
log.Error("point balance is not enough,userId=%d jobType=%s ", ctx.User.ID, string(models.JobTypeBenchmark)) | |||
cloudBrainNewDataPrepare(ctx) | |||
ctx.RenderWithErr(ctx.Tr("points.insufficient_points_balance"), tplModelArtsNotebookNew, &form) | |||
return | |||
} | |||
count, err := models.GetCloudbrainNotebookCountByUserID(ctx.User.ID) | |||
if err != nil { | |||
log.Error("GetCloudbrainNotebookCountByUserID failed:%v", err, ctx.Data["MsgID"]) | |||
@@ -262,6 +256,13 @@ func Notebook2Create(ctx *context.Context, form auth.CreateModelArtsNotebookForm | |||
ctx.RenderWithErr("Resource specification not available", tplModelArtsNotebookNew, &form) | |||
return | |||
} | |||
if !account.IsPointBalanceEnough(ctx.User.ID, spec.UnitPrice) { | |||
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"), tplModelArtsNotebookNew, &form) | |||
return | |||
} | |||
err = modelarts.GenerateNotebook2(ctx, displayJobName, jobName, uuid, description, imageId, spec) | |||
if err != nil { | |||
log.Error("GenerateNotebook2 failed, %v", err, ctx.Data["MsgID"]) | |||
@@ -434,8 +435,8 @@ func NotebookRestart(ctx *context.Context) { | |||
break | |||
} | |||
if !account.IsPointBalanceEnough(ctx.User.ID, task.JobType, task.Type, task.ResourceSpecId, task.FlavorCode) { | |||
log.Error("point balance is not enough,userId=%d jobType=%s resourceSpecId=%d", ctx.User.ID, task.JobType, task.ResourceSpecId) | |||
if !account.IsPointBalanceEnough(ctx.User.ID, spec.UnitPrice) { | |||
log.Error("point balance is not enough,userId=%d specId=%d", ctx.User.ID, spec.ID) | |||
resultCode = "-1" | |||
errorMsg = ctx.Tr("points.insufficient_points_balance") | |||
break | |||
@@ -1102,12 +1103,6 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) | |||
VersionCount := modelarts.VersionCountOne | |||
EngineName := form.EngineName | |||
if !account.IsPointBalanceEnough(ctx.User.ID, string(models.JobTypeTrain), models.TypeCloudBrainTwo, 0, flavorCode) { | |||
log.Error("point balance is not enough,userId=%d jobType=%s", ctx.User.ID, string(models.JobTypeBenchmark)) | |||
cloudBrainNewDataPrepare(ctx) | |||
ctx.RenderWithErr(ctx.Tr("points.insufficient_points_balance"), tplModelArtsTrainJobNew, &form) | |||
return | |||
} | |||
count, err := models.GetCloudbrainTrainJobCountByUserID(ctx.User.ID) | |||
if err != nil { | |||
log.Error("GetCloudbrainTrainJobCountByUserID failed:%v", err, ctx.Data["MsgID"]) | |||
@@ -1148,6 +1143,13 @@ 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) { | |||
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) | |||
return | |||
} | |||
//Determine whether the task name of the task in the project is duplicated | |||
tasks, err := models.GetCloudbrainsByDisplayJobName(repo.ID, string(models.JobTypeTrain), displayJobName) | |||
if err == nil { | |||
@@ -2026,12 +2028,6 @@ func InferenceJobCreate(ctx *context.Context, form auth.CreateModelArtsInference | |||
ckptUrl := "/" + form.TrainUrl + form.CkptName | |||
log.Info("ckpt url:" + ckptUrl) | |||
if !account.IsPointBalanceEnough(ctx.User.ID, string(models.JobTypeInference), models.TypeCloudBrainTwo, 0, flavorCode) { | |||
log.Error("point balance is not enough,userId=%d jobType=%s ", ctx.User.ID, string(models.JobTypeBenchmark)) | |||
inferenceJobErrorNewDataPrepare(ctx, form) | |||
ctx.RenderWithErr(ctx.Tr("points.insufficient_points_balance"), tplModelArtsInferenceJobNew, &form) | |||
return | |||
} | |||
count, err := models.GetCloudbrainInferenceJobCountByUserID(ctx.User.ID) | |||
if err != nil { | |||
log.Error("GetCloudbrainInferenceJobCountByUserID failed:%v", err, ctx.Data["MsgID"]) | |||
@@ -2090,6 +2086,13 @@ func InferenceJobCreate(ctx *context.Context, form auth.CreateModelArtsInference | |||
ctx.RenderWithErr("Resource specification not available", tplModelArtsInferenceJobNew, &form) | |||
return | |||
} | |||
if !account.IsPointBalanceEnough(ctx.User.ID, spec.UnitPrice) { | |||
log.Error("point balance is not enough,userId=%d specId=%d ", ctx.User.ID, spec.ID) | |||
inferenceJobErrorNewDataPrepare(ctx, form) | |||
ctx.RenderWithErr(ctx.Tr("points.insufficient_points_balance"), tplModelArtsInferenceJobNew, &form) | |||
return | |||
} | |||
//todo: del the codeLocalPath | |||
_, err = ioutil.ReadDir(codeLocalPath) | |||
if err == nil { | |||
@@ -20,7 +20,10 @@ func StartAndGetCloudBrainPointDeductTask(task models.Cloudbrain) (*models.Rewar | |||
return nil, nil | |||
} | |||
unitPrice := models.GetCloudbrainTaskUnitPrice(task) | |||
unitPrice, err := models.GetCloudbrainTaskUnitPrice(task.ID) | |||
if err != nil { | |||
return nil, err | |||
} | |||
if unitPrice == 0 { | |||
log.Debug("finish StartAndGetCloudBrainPointDeductTask, UnitPrice = 0 task.ID=%d", task.ID) | |||
return nil, nil | |||
@@ -16,7 +16,7 @@ func NewRewardPeriodicTask(operateRecordId string, opts *models.StartPeriodicTas | |||
task := &models.RewardPeriodicTask{} | |||
task.DelaySeconds = int64(opts.Delay.Seconds()) | |||
task.IntervalSeconds = int64(opts.Interval.Seconds()) | |||
task.Amount = opts.UnitAmount | |||
task.Amount = int64(opts.UnitAmount) | |||
task.OperateSerialNo = operateRecordId | |||
task.Status = models.PeriodicTaskStatusRunning | |||
task.NextExecuteTime = timeutil.TimeStamp(opts.StartTime.Add(opts.Delay).Unix()) | |||
@@ -69,18 +69,11 @@ func InitAccount(userId int64) (*models.PointAccount, error) { | |||
} | |||
//IsPointBalanceEnough check whether the user's point balance is bigger than task unit price | |||
func IsPointBalanceEnough(targetUserId int64, jobType string, clusterType int, resourceSpecId int, flavorCode string) bool { | |||
func IsPointBalanceEnough(targetUserId int64, unitPrice int) bool { | |||
if !setting.CloudBrainPaySwitch { | |||
return true | |||
} | |||
t := models.Cloudbrain{ | |||
Type: clusterType, | |||
JobType: jobType, | |||
ResourceSpecId: resourceSpecId, | |||
FlavorCode: flavorCode, | |||
} | |||
uniPrice := models.GetCloudbrainTaskUnitPrice(t) | |||
if uniPrice == 0 { | |||
if unitPrice == 0 { | |||
return true | |||
} | |||
a, err := GetAccount(targetUserId) | |||
@@ -88,8 +81,7 @@ func IsPointBalanceEnough(targetUserId int64, jobType string, clusterType int, r | |||
log.Error("IsPointBalanceEnough GetAccount error,err=%v", err) | |||
return false | |||
} | |||
return a.Balance >= uniPrice | |||
return a.Balance >= int64(unitPrice) | |||
} | |||
func SearchPointAccount(opt models.SearchPointAccountOpts) (*models.SearchPointAccountResponse, error) { | |||
@@ -2,6 +2,7 @@ package wechat | |||
import ( | |||
"code.gitea.io/gitea/models" | |||
"code.gitea.io/gitea/modules/auth/wechat" | |||
"code.gitea.io/gitea/modules/notification" | |||
"code.gitea.io/gitea/modules/redis/redis_client" | |||
"code.gitea.io/gitea/modules/redis/redis_key" | |||
@@ -144,17 +145,17 @@ func HandleScanEvent(we WechatMsg) string { | |||
if val == "" { | |||
return "" | |||
} | |||
qrCache := new(QRCode4BindCache) | |||
qrCache := new(wechat.QRCode4BindCache) | |||
json.Unmarshal([]byte(val), qrCache) | |||
if qrCache.Status == BIND_STATUS_UNBIND { | |||
err := BindWechat(qrCache.UserId, we.FromUserName) | |||
if qrCache.Status == wechat.BIND_STATUS_UNBIND { | |||
err := wechat.BindWechat(qrCache.UserId, we.FromUserName) | |||
if err != nil { | |||
if err, ok := err.(WechatBindError); ok { | |||
if err, ok := err.(wechat.WechatBindError); ok { | |||
return err.Reply | |||
} | |||
return BIND_REPLY_FAILED_DEFAULT | |||
return wechat.BIND_REPLY_FAILED_DEFAULT | |||
} | |||
qrCache.Status = BIND_STATUS_BOUND | |||
qrCache.Status = wechat.BIND_STATUS_BOUND | |||
jsonStr, _ := json.Marshal(qrCache) | |||
redis_client.Setex(redis_key.WechatBindingUserIdKey(sceneStr), string(jsonStr), 60*time.Second) | |||
} | |||
@@ -163,7 +164,7 @@ func HandleScanEvent(we WechatMsg) string { | |||
notification.NotifyWechatBind(u, we.FromUserName) | |||
} | |||
return BIND_REPLY_SUCCESS | |||
return wechat.BIND_REPLY_SUCCESS | |||
} | |||
func HandleSubscribeEvent(we WechatMsg) *WechatReplyContent { |