diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 86af80235..06fbea5b3 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -1663,6 +1663,14 @@ func GetCloudbrainCountByUserID(userID int64, jobType string) (int, error) { return int(count), err } +func GetCloudbrainRunCountByRepoID(repoID int64) (int, error) { + count, err := x.In("status", JobWaiting, JobRunning, ModelArtsCreateQueue, ModelArtsCreating, ModelArtsStarting, + ModelArtsReadyToStart, ModelArtsResizing, ModelArtsStartQueuing, ModelArtsRunning, ModelArtsRestarting, ModelArtsTrainJobInit, + ModelArtsTrainJobImageCreating, ModelArtsTrainJobSubmitTrying, ModelArtsTrainJobWaiting, ModelArtsTrainJobRunning, + ModelArtsTrainJobScaling, ModelArtsTrainJobCheckInit, ModelArtsTrainJobCheckRunning, ModelArtsTrainJobCheckRunningCompleted).And("repo_id = ?", repoID).Count(new(Cloudbrain)) + return int(count), err +} + func GetBenchmarkCountByUserID(userID int64) (int, error) { count, err := x.In("status", JobWaiting, JobRunning).And("(job_type = ? or job_type = ? or job_type = ?) and user_id = ? and type = ?", string(JobTypeBenchmark), string(JobTypeBrainScore), string(JobTypeSnn4imagenet), userID, TypeCloudBrainOne).Count(new(Cloudbrain)) return int(count), err diff --git a/modules/auth/wechat/access_token.go b/modules/auth/wechat/access_token.go index 0a63bc2de..f9516e3e1 100644 --- a/modules/auth/wechat/access_token.go +++ b/modules/auth/wechat/access_token.go @@ -9,7 +9,7 @@ import ( const EMPTY_REDIS_VAL = "Nil" -var accessTokenLock = redis_lock.NewDistributeLock() +var accessTokenLock = redis_lock.NewDistributeLock(redis_key.AccessTokenLockKey()) func GetWechatAccessToken() string { token, _ := redis_client.Get(redis_key.WechatAccessTokenKey()) @@ -28,15 +28,15 @@ func GetWechatAccessToken() string { } func refreshAccessToken() { - if ok := accessTokenLock.Lock(redis_key.AccessTokenLockKey(), 3*time.Second); ok { - defer accessTokenLock.UnLock(redis_key.AccessTokenLockKey()) + if ok := accessTokenLock.Lock(3 * time.Second); ok { + defer accessTokenLock.UnLock() callAccessTokenAndUpdateCache() } } func refreshAndGetAccessToken() string { - if ok := accessTokenLock.LockWithWait(redis_key.AccessTokenLockKey(), 3*time.Second, 3*time.Second); ok { - defer accessTokenLock.UnLock(redis_key.AccessTokenLockKey()) + if ok := accessTokenLock.LockWithWait(3*time.Second, 3*time.Second); ok { + defer accessTokenLock.UnLock() token, _ := redis_client.Get(redis_key.WechatAccessTokenKey()) if token != "" { if token == EMPTY_REDIS_VAL { diff --git a/modules/redis/redis_lock/lock.go b/modules/redis/redis_lock/lock.go index 0faed3237..b8cd837f1 100644 --- a/modules/redis/redis_lock/lock.go +++ b/modules/redis/redis_lock/lock.go @@ -6,22 +6,23 @@ import ( ) type DistributeLock struct { + lockKey string } -func NewDistributeLock() *DistributeLock { - return &DistributeLock{} +func NewDistributeLock(lockKey string) *DistributeLock { + return &DistributeLock{lockKey: lockKey} } -func (lock *DistributeLock) Lock(lockKey string, expireTime time.Duration) bool { - isOk, _ := redis_client.Setnx(lockKey, "", expireTime) +func (lock *DistributeLock) Lock(expireTime time.Duration) bool { + isOk, _ := redis_client.Setnx(lock.lockKey, "", expireTime) return isOk } -func (lock *DistributeLock) LockWithWait(lockKey string, expireTime time.Duration, waitTime time.Duration) bool { +func (lock *DistributeLock) LockWithWait(expireTime time.Duration, waitTime time.Duration) bool { start := time.Now().Unix() * 1000 duration := waitTime.Milliseconds() for { - isOk, _ := redis_client.Setnx(lockKey, "", expireTime) + isOk, _ := redis_client.Setnx(lock.lockKey, "", expireTime) if isOk { return true } @@ -34,7 +35,7 @@ func (lock *DistributeLock) LockWithWait(lockKey string, expireTime time.Duratio return false } -func (lock *DistributeLock) UnLock(lockKey string) error { - _, err := redis_client.Del(lockKey) +func (lock *DistributeLock) UnLock() error { + _, err := redis_client.Del(lock.lockKey) return err } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 15afb37ca..c52a369ce 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -817,6 +817,7 @@ settings.delete_notices_1= - This operation CANNOT be undone. settings.delete_notices_2= - This operation will permanently delete the %s dataset. settings.delete_notices_fork_1= - Forks of this dataset will become independent after deletion. settings.deletion_success= The dataset has been deleted. +settings.deletion_notice_cloudbrain = you need to stop the cloudbrain task under the project before remove the project! task.machine_translation= machine translation task.question_answering_system= question answering system task.information_retrieval= information retrieval diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index fc5f89ccb..cb1c7565a 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -1931,6 +1931,7 @@ settings.delete_notices_1=- 此操作 不可以 被回滚。 settings.delete_notices_2=- 此操作将永久删除项目 %s,包括 Git 数据、 任务、评论、百科和协作者的操作权限。 settings.delete_notices_fork_1=- 在此项目删除后,它的派生项目将变成独立项目。 settings.deletion_success=项目已被删除。 +settings.deletion_notice_cloudbrain=请先停止项目内正在运行的云脑任务,然后再删除项目。 settings.update_settings_success=项目设置已更新。 settings.transfer_owner=新拥有者 settings.make_transfer=开始转移 diff --git a/routers/repo/setting.go b/routers/repo/setting.go index af28f3290..a72af3858 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -6,7 +6,6 @@ package repo import ( - "code.gitea.io/gitea/modules/notification" "errors" "fmt" "io/ioutil" @@ -15,6 +14,8 @@ import ( "strings" "time" + "code.gitea.io/gitea/modules/notification" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" @@ -477,16 +478,25 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil) return } - - if err := repo_service.DeleteRepository(ctx.User, ctx.Repo.Repository); err != nil { - ctx.ServerError("DeleteRepository", err) + count, err := models.GetCloudbrainRunCountByRepoID(repo.ID) + if err != nil { + ctx.ServerError("GetCloudbrainCountByRepoID failed", err) return - } - log.Trace("Repository deleted: %s/%s", ctx.Repo.Owner.Name, repo.Name) - go StopJobsByRepoID(repo.ID) + } else { + if count >= 1 { + ctx.RenderWithErr(ctx.Tr("repo.settings.deletion_notice_cloudbrain"), tplSettingsOptions, nil) + return + } + if err := repo_service.DeleteRepository(ctx.User, ctx.Repo.Repository); err != nil { + ctx.ServerError("DeleteRepository", err) + return + } + log.Trace("Repository deleted: %s/%s", ctx.Repo.Owner.Name, repo.Name) + go StopJobsByRepoID(repo.ID) - ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success")) - ctx.Redirect(ctx.Repo.Owner.DashboardLink()) + ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success")) + ctx.Redirect(ctx.Repo.Owner.DashboardLink()) + } case "delete-wiki": if !ctx.Repo.IsOwner() { diff --git a/templates/custom/select_dataset.tmpl b/templates/custom/select_dataset.tmpl index befd186c5..d545f487e 100644 --- a/templates/custom/select_dataset.tmpl +++ b/templates/custom/select_dataset.tmpl @@ -1,138 +1,171 @@ - - +
{{if eq .cloudbraintype 0}} - + {{else}} {{end}} - {{.i18n.Tr "dataset.select_dataset"}} - -
- - -
- - - -
-
-
${dataset.Repo.OwnerName}/${dataset.Repo.Alias}${dataset.Name}
-
- - - - ${dataset.Description} -
-
-
- - - - 解压中 - - - - 解压失败 - -
+ + {{.i18n.Tr "dataset.select_dataset"}} + +
+
+ +
- - - - -
-
-
${dataset.Repo.OwnerName}/${dataset.Repo.Alias}${dataset.Name}
-
- - - - ${dataset.Description} + + + +
+
+
${dataset.Repo.OwnerName}/${dataset.Repo.Alias}${dataset.Name}
+
+ + + + ${dataset.Description} +
+
+
+ + + + 解压中 + + + + 解压失败 + +
+
+
+ +
+
+
${dataset.Repo.OwnerName}/${dataset.Repo.Alias}${dataset.Name}
+
+ + + + ${dataset.Description} +
+
+
+ + + + 解压中 + + + + 解压失败 + +
-
-
- - - - 解压中 - - - - 解压失败 - -
-
- - -
-
-
${dataset.Repo.OwnerName}/${dataset.Repo.Alias}${dataset.Name}
-
- - - - ${dataset.Description} + + +
+
+
${dataset.Repo.OwnerName}/${dataset.Repo.Alias}${dataset.Name}
+
+ + + + ${dataset.Description} +
+
+
+ + + + 解压中 + + + + 解压失败 + +
-
-
- - - - 解压中 - - - - 解压失败 - -
-
- - -
-
-
${dataset.Repo.OwnerName}/${dataset.Repo.Alias}${dataset.Name}
-
- - - - ${dataset.Description} + + +
+
+
${dataset.Repo.OwnerName}/${dataset.Repo.Alias}${dataset.Name}
+
+ + + + ${dataset.Description} +
+
+
+ + + + 解压中 + + + + 解压失败 + +
-
-
- - - - 解压中 - - - - 解压失败 - -
-
- - -
- - -
+ + +
+ + +
+
-
+
\ No newline at end of file diff --git a/templates/custom/select_dataset_train.tmpl b/templates/custom/select_dataset_train.tmpl index 28fce2490..f1d2abaf3 100644 --- a/templates/custom/select_dataset_train.tmpl +++ b/templates/custom/select_dataset_train.tmpl @@ -1,142 +1,179 @@ - - +
{{if or (.benchmarkMode) (.newInference)}} -       {{else}}{{.i18n.Tr "dataset.dataset"}}    {{end}} +       {{else}}{{.i18n.Tr "dataset.dataset"}}    {{end}} {{else}}     {{end}} - {{if .benchmarkMode}}{{.i18n.Tr "repo.modelarts.infer_job.select_model"}}{{else}}{{.i18n.Tr "dataset.select_dataset"}}{{end}} + + {{if .benchmarkMode}}{{.i18n.Tr "repo.modelarts.infer_job.select_model"}}{{else}}{{.i18n.Tr "dataset.select_dataset"}}{{end}} + {{if .benchmarkMode}} 说明:先使用数据集功能上传模型,然后从数据集列表选模型。 {{end}} - -
- - -
- - - -
-
-
${dataset.Repo.OwnerName}/${dataset.Repo.Alias} ${dataset.Name}
-
- - - - ${dataset.Description} -
-
-
- - - - 解压中 - - - - 解压失败 - -
+ +
+
+ +
- - {{if not .benchmarkMode}} - - -
-
-
${dataset.Repo.OwnerName}/${dataset.Repo.Alias}${dataset.Name}
-
- - - - ${dataset.Description} + + + +
+
+
${dataset.Repo.OwnerName}/${dataset.Repo.Alias} + ${dataset.Name} +
+
+ + + + ${dataset.Description} +
+
+
+ + + + 解压中 + + + + 解压失败 + +
-
-
- - - - 解压中 - - - - 解压失败 - -
-
- - -
-
-
${dataset.Repo.OwnerName}/${dataset.Repo.Alias}${dataset.Name}
-
- - - - ${dataset.Description} + {{if not .benchmarkMode}} + + +
+
+
${dataset.Repo.OwnerName}/${dataset.Repo.Alias}${dataset.Name}
+
+ + + + ${dataset.Description} +
+
+
+ + + + 解压中 + + + + 解压失败 + +
-
-
- - - - 解压中 - - - - 解压失败 - -
-
- - -
-
-
${dataset.Repo.OwnerName}/${dataset.Repo.Alias}${dataset.Name}
-
- - - - ${dataset.Description} + + +
+
+
${dataset.Repo.OwnerName}/${dataset.Repo.Alias}${dataset.Name}
+
+ + + + ${dataset.Description} +
+
+
+ + + + 解压中 + + + + 解压失败 + +
+
+ +
+ +
+
+
${dataset.Repo.OwnerName}/${dataset.Repo.Alias}${dataset.Name}
+
+ + + + ${dataset.Description} +
+
+
+ + + + 解压中 + + + + 解压失败 + +
-
-
- - - - 解压中 - - - - 解压失败 - -
-
- - {{end}} - -
- - -
+ + {{end}} + +
+ + +
+
-
+
\ No newline at end of file diff --git a/web_src/js/index.js b/web_src/js/index.js index ed8fb3473..6e10f2f75 100755 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -3867,7 +3867,7 @@ function initVueDataset() { cloudbrainType: 0, dataset_uuid: '', dataset_name: '', - loadingDataIndex: true, + loadingDataIndex: false, timer: null, ruleForm: { title: '', @@ -4338,6 +4338,7 @@ function initVueDataset() { } }, getCurrentRepoDataset(repoLink, type) { + clearInterval(this.timer) this.loadingDataIndex = true let url = repoLink + '/datasets/current_repo' @@ -4348,12 +4349,17 @@ function initVueDataset() { q: this.searchDataItem } }).then((res) => { - this.currentRepoDataset = JSON.parse(res.data.data) - const checkStatuDataset = this.currentRepoDataset.filter(item => item.DecompressState === 2) - if (checkStatuDataset.length > 0) { - this.polling(checkStatuDataset, repoLink) + if (res.result_code == '0') { + this.currentRepoDataset = JSON.parse(res.data.data) + const checkStatuDataset = this.currentRepoDataset.filter(item => item.DecompressState === 2) + if (checkStatuDataset.length > 0) { + this.polling(checkStatuDataset, repoLink) + } + this.totalnums = parseInt(res.data.count) + } else { + this.totalnums = 0 } - this.totalnums = parseInt(res.data.count) + this.loadingDataIndex = false }) },