Browse Source

优化代码

tags/v1.21.12.1^2
ychao_1983 4 years ago
parent
commit
ace4ec5ca6
1 changed files with 11 additions and 10 deletions
  1. +11
    -10
      modules/cloudbrain/cloudbrain.go

+ 11
- 10
modules/cloudbrain/cloudbrain.go View File

@@ -31,6 +31,9 @@ var (
)

func isAdminOrOwnerOrJobCreater(ctx *context.Context, job *models.Cloudbrain, err error) bool {
if !ctx.IsSigned {
return false
}
log.Info("is repo owner:" + strconv.FormatBool(ctx.IsUserRepoOwner()))
log.Info("is user admin:" + strconv.FormatBool(ctx.IsUserSiteAdmin()))
if err != nil {
@@ -48,16 +51,12 @@ func CanDeleteDebugJob(ctx *context.Context, job *models.Cloudbrain) bool {
if job.Status != string(models.JobStopped) && job.Status != string(models.JobFailed) && job.Status != string(models.ModelArtsStartFailed) && job.Status != string(models.ModelArtsCreateFailed) {
return false
}
if !ctx.IsSigned {
return false
}

return isAdminOrOwnerOrJobCreater(ctx, job, nil)
}

func CanDeleteTrainJob(ctx *context.Context, job *models.Cloudbrain) bool {
if !ctx.IsSigned {
return false
}

return isAdminOrOwnerOrJobCreater(ctx, job, nil)
}

@@ -74,7 +73,9 @@ func CanModifyJob(ctx *context.Context, job *models.Cloudbrain) bool {
}

func isAdminOrJobCreater(ctx *context.Context, job *models.Cloudbrain, err error) bool {

if !ctx.IsSigned {
return false
}
if err != nil {
return ctx.IsUserSiteAdmin()
} else {
@@ -125,7 +126,7 @@ func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath,
log.Error("no such resourceSpecId(%d)", resourceSpecId, ctx.Data["MsgID"])
return errors.New("no such resourceSpec")
}
jobResult, err := CreateJob(jobName, models.CreateJobParams{
JobName: jobName,
RetryCount: 1,
@@ -210,8 +211,8 @@ func GenerateTask(ctx *context.Context, jobName, image, command, uuid, codePath,
JobName: jobName,
SubTaskName: SubTaskName,
JobType: jobType,
Type: models.TypeCloudBrainOne,
Uuid: uuid,
Type: models.TypeCloudBrainOne,
Uuid: uuid,
})

if err != nil {


Loading…
Cancel
Save