| @@ -1566,6 +1566,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 | |||
| @@ -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 { | |||
| @@ -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 | |||
| } | |||
| @@ -817,6 +817,7 @@ settings.delete_notices_1= - This operation <strong>CANNOT</strong> be undone. | |||
| settings.delete_notices_2= - This operation will permanently delete the <strong>%s</strong> 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 | |||
| @@ -1931,6 +1931,7 @@ settings.delete_notices_1=- 此操作 <strong>不可以</strong> 被回滚。 | |||
| settings.delete_notices_2=- 此操作将永久删除项目 <strong>%s</strong>,包括 Git 数据、 任务、评论、百科和协作者的操作权限。 | |||
| settings.delete_notices_fork_1=- 在此项目删除后,它的派生项目将变成独立项目。 | |||
| settings.deletion_success=项目已被删除。 | |||
| settings.deletion_notice_cloudbrain=请先停止项目内正在运行的云脑任务,然后再删除项目。 | |||
| settings.update_settings_success=项目设置已更新。 | |||
| settings.transfer_owner=新拥有者 | |||
| settings.make_transfer=开始转移 | |||
| @@ -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() { | |||