summaryrefslogtreecommitdiffstats
path: root/services/cron
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-24 17:49:20 +0800
committerGitHub <noreply@github.com>2021-11-24 17:49:20 +0800
commita666829a37be6f9fd98f9e7dd1767c420f7f3b32 (patch)
tree9ab1434b759a8a2cb275a83149903a823851e309 /services/cron
parent4e7ca946da2a2642a62f114825129bf5d7ed9196 (diff)
downloadgitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.tar.gz
gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.zip
Move user related model into models/user (#17781)
* Move user related model into models/user * Fix lint for windows * Fix windows lint * Fix windows lint * Move some tests in models * Merge
Diffstat (limited to 'services/cron')
-rw-r--r--services/cron/setting.go6
-rw-r--r--services/cron/tasks.go12
-rw-r--r--services/cron/tasks_basic.go17
-rw-r--r--services/cron/tasks_extended.go23
4 files changed, 30 insertions, 28 deletions
diff --git a/services/cron/setting.go b/services/cron/setting.go
index a0393e23dc..3d9495764d 100644
--- a/services/cron/setting.go
+++ b/services/cron/setting.go
@@ -7,7 +7,7 @@ package cron
import (
"time"
- "code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"github.com/unknwon/i18n"
)
@@ -17,7 +17,7 @@ type Config interface {
IsEnabled() bool
DoRunAtStart() bool
GetSchedule() string
- FormatMessage(name, status string, doer *models.User, args ...interface{}) string
+ FormatMessage(name, status string, doer *user_model.User, args ...interface{}) string
DoNoticeOnSuccess() bool
}
@@ -70,7 +70,7 @@ func (b *BaseConfig) DoNoticeOnSuccess() bool {
}
// FormatMessage returns a message for the task
-func (b *BaseConfig) FormatMessage(name, status string, doer *models.User, args ...interface{}) string {
+func (b *BaseConfig) FormatMessage(name, status string, doer *user_model.User, args ...interface{}) string {
realArgs := make([]interface{}, 0, len(args)+2)
realArgs = append(realArgs, i18n.Tr("en-US", "admin.dashboard."+name))
if doer == nil {
diff --git a/services/cron/tasks.go b/services/cron/tasks.go
index 732eead930..75bb4993c0 100644
--- a/services/cron/tasks.go
+++ b/services/cron/tasks.go
@@ -10,9 +10,9 @@ import (
"reflect"
"sync"
- "code.gitea.io/gitea/models"
admin_model "code.gitea.io/gitea/models/admin"
"code.gitea.io/gitea/models/db"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
@@ -29,7 +29,7 @@ type Task struct {
lock sync.Mutex
Name string
config Config
- fun func(context.Context, *models.User, Config) error
+ fun func(context.Context, *user_model.User, Config) error
ExecTimes int64
}
@@ -55,7 +55,7 @@ func (t *Task) GetConfig() Config {
// Run will run the task incrementing the cron counter with no user defined
func (t *Task) Run() {
- t.RunWithUser(&models.User{
+ t.RunWithUser(&user_model.User{
ID: -1,
Name: "(Cron)",
LowerName: "(cron)",
@@ -63,7 +63,7 @@ func (t *Task) Run() {
}
// RunWithUser will run the task incrementing the cron counter at the time with User
-func (t *Task) RunWithUser(doer *models.User, config Config) {
+func (t *Task) RunWithUser(doer *user_model.User, config Config) {
if !taskStatusTable.StartIfNotRunning(t.Name) {
return
}
@@ -118,7 +118,7 @@ func GetTask(name string) *Task {
}
// RegisterTask allows a task to be registered with the cron service
-func RegisterTask(name string, config Config, fun func(context.Context, *models.User, Config) error) error {
+func RegisterTask(name string, config Config, fun func(context.Context, *user_model.User, Config) error) error {
log.Debug("Registering task: %s", name)
_, err := setting.GetCronSettings(name, config)
if err != nil {
@@ -163,7 +163,7 @@ func RegisterTask(name string, config Config, fun func(context.Context, *models.
}
// RegisterTaskFatal will register a task but if there is an error log.Fatal
-func RegisterTaskFatal(name string, config Config, fun func(context.Context, *models.User, Config) error) {
+func RegisterTaskFatal(name string, config Config, fun func(context.Context, *user_model.User, Config) error) {
if err := RegisterTask(name, config, fun); err != nil {
log.Fatal("Unable to register cron task %s Error: %v", name, err)
}
diff --git a/services/cron/tasks_basic.go b/services/cron/tasks_basic.go
index 4832ca98a7..814f6eae4e 100644
--- a/services/cron/tasks_basic.go
+++ b/services/cron/tasks_basic.go
@@ -9,6 +9,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/auth"
@@ -33,7 +34,7 @@ func registerUpdateMirrorTask() {
},
PullLimit: 50,
PushLimit: 50,
- }, func(ctx context.Context, _ *models.User, cfg Config) error {
+ }, func(ctx context.Context, _ *user_model.User, cfg Config) error {
umtc := cfg.(*UpdateMirrorTaskConfig)
return mirror_service.Update(ctx, umtc.PullLimit, umtc.PushLimit)
})
@@ -53,7 +54,7 @@ func registerRepoHealthCheck() {
},
Timeout: 60 * time.Second,
Args: []string{},
- }, func(ctx context.Context, _ *models.User, config Config) error {
+ }, func(ctx context.Context, _ *user_model.User, config Config) error {
rhcConfig := config.(*RepoHealthCheckConfig)
return repository_service.GitFsck(ctx, rhcConfig.Timeout, rhcConfig.Args)
})
@@ -64,7 +65,7 @@ func registerCheckRepoStats() {
Enabled: true,
RunAtStart: true,
Schedule: "@midnight",
- }, func(ctx context.Context, _ *models.User, _ Config) error {
+ }, func(ctx context.Context, _ *user_model.User, _ Config) error {
return models.CheckRepoStats(ctx)
})
}
@@ -77,7 +78,7 @@ func registerArchiveCleanup() {
Schedule: "@midnight",
},
OlderThan: 24 * time.Hour,
- }, func(ctx context.Context, _ *models.User, config Config) error {
+ }, func(ctx context.Context, _ *user_model.User, config Config) error {
acConfig := config.(*OlderThanConfig)
return models.DeleteOldRepositoryArchives(ctx, acConfig.OlderThan)
})
@@ -91,7 +92,7 @@ func registerSyncExternalUsers() {
Schedule: "@midnight",
},
UpdateExisting: true,
- }, func(ctx context.Context, _ *models.User, config Config) error {
+ }, func(ctx context.Context, _ *user_model.User, config Config) error {
realConfig := config.(*UpdateExistingConfig)
return auth.SyncExternalUsers(ctx, realConfig.UpdateExisting)
})
@@ -105,7 +106,7 @@ func registerDeletedBranchesCleanup() {
Schedule: "@midnight",
},
OlderThan: 24 * time.Hour,
- }, func(ctx context.Context, _ *models.User, config Config) error {
+ }, func(ctx context.Context, _ *user_model.User, config Config) error {
realConfig := config.(*OlderThanConfig)
models.RemoveOldDeletedBranches(ctx, realConfig.OlderThan)
return nil
@@ -117,7 +118,7 @@ func registerUpdateMigrationPosterID() {
Enabled: true,
RunAtStart: true,
Schedule: "@midnight",
- }, func(ctx context.Context, _ *models.User, _ Config) error {
+ }, func(ctx context.Context, _ *user_model.User, _ Config) error {
return migrations.UpdateMigrationPosterID(ctx)
})
}
@@ -132,7 +133,7 @@ func registerCleanupHookTaskTable() {
CleanupType: "OlderThan",
OlderThan: 168 * time.Hour,
NumberToKeep: 10,
- }, func(ctx context.Context, _ *models.User, config Config) error {
+ }, func(ctx context.Context, _ *user_model.User, config Config) error {
realConfig := config.(*CleanupHookTaskConfig)
return webhook.CleanupHookTaskTable(ctx, webhook.ToHookTaskCleanupType(realConfig.CleanupType), realConfig.OlderThan, realConfig.NumberToKeep)
})
diff --git a/services/cron/tasks_extended.go b/services/cron/tasks_extended.go
index 95293b1c1d..26dbe548a7 100644
--- a/services/cron/tasks_extended.go
+++ b/services/cron/tasks_extended.go
@@ -9,6 +9,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/updatechecker"
repo_service "code.gitea.io/gitea/services/repository"
@@ -23,7 +24,7 @@ func registerDeleteInactiveUsers() {
Schedule: "@annually",
},
OlderThan: 0 * time.Second,
- }, func(ctx context.Context, _ *models.User, config Config) error {
+ }, func(ctx context.Context, _ *user_model.User, config Config) error {
olderThanConfig := config.(*OlderThanConfig)
return user_service.DeleteInactiveUsers(ctx, olderThanConfig.OlderThan)
})
@@ -34,7 +35,7 @@ func registerDeleteRepositoryArchives() {
Enabled: false,
RunAtStart: false,
Schedule: "@annually",
- }, func(ctx context.Context, _ *models.User, _ Config) error {
+ }, func(ctx context.Context, _ *user_model.User, _ Config) error {
return repo_service.DeleteRepositoryArchives(ctx)
})
}
@@ -53,7 +54,7 @@ func registerGarbageCollectRepositories() {
},
Timeout: time.Duration(setting.Git.Timeout.GC) * time.Second,
Args: setting.Git.GCArgs,
- }, func(ctx context.Context, _ *models.User, config Config) error {
+ }, func(ctx context.Context, _ *user_model.User, config Config) error {
rhcConfig := config.(*RepoHealthCheckConfig)
return repo_service.GitGcRepos(ctx, rhcConfig.Timeout, rhcConfig.Args...)
})
@@ -64,7 +65,7 @@ func registerRewriteAllPublicKeys() {
Enabled: false,
RunAtStart: false,
Schedule: "@every 72h",
- }, func(_ context.Context, _ *models.User, _ Config) error {
+ }, func(_ context.Context, _ *user_model.User, _ Config) error {
return models.RewriteAllPublicKeys()
})
}
@@ -74,7 +75,7 @@ func registerRewriteAllPrincipalKeys() {
Enabled: false,
RunAtStart: false,
Schedule: "@every 72h",
- }, func(_ context.Context, _ *models.User, _ Config) error {
+ }, func(_ context.Context, _ *user_model.User, _ Config) error {
return models.RewriteAllPrincipalKeys()
})
}
@@ -84,7 +85,7 @@ func registerRepositoryUpdateHook() {
Enabled: false,
RunAtStart: false,
Schedule: "@every 72h",
- }, func(ctx context.Context, _ *models.User, _ Config) error {
+ }, func(ctx context.Context, _ *user_model.User, _ Config) error {
return repo_service.SyncRepositoryHooks(ctx)
})
}
@@ -94,7 +95,7 @@ func registerReinitMissingRepositories() {
Enabled: false,
RunAtStart: false,
Schedule: "@every 72h",
- }, func(ctx context.Context, _ *models.User, _ Config) error {
+ }, func(ctx context.Context, _ *user_model.User, _ Config) error {
return repo_service.ReinitMissingRepositories(ctx)
})
}
@@ -104,7 +105,7 @@ func registerDeleteMissingRepositories() {
Enabled: false,
RunAtStart: false,
Schedule: "@every 72h",
- }, func(ctx context.Context, user *models.User, _ Config) error {
+ }, func(ctx context.Context, user *user_model.User, _ Config) error {
return repo_service.DeleteMissingRepositories(ctx, user)
})
}
@@ -114,7 +115,7 @@ func registerRemoveRandomAvatars() {
Enabled: false,
RunAtStart: false,
Schedule: "@every 72h",
- }, func(ctx context.Context, _ *models.User, _ Config) error {
+ }, func(ctx context.Context, _ *user_model.User, _ Config) error {
return models.RemoveRandomAvatars(ctx)
})
}
@@ -127,7 +128,7 @@ func registerDeleteOldActions() {
Schedule: "@every 168h",
},
OlderThan: 365 * 24 * time.Hour,
- }, func(ctx context.Context, _ *models.User, config Config) error {
+ }, func(ctx context.Context, _ *user_model.User, config Config) error {
olderThanConfig := config.(*OlderThanConfig)
return models.DeleteOldActions(olderThanConfig.OlderThan)
})
@@ -145,7 +146,7 @@ func registerUpdateGiteaChecker() {
Schedule: "@every 168h",
},
HTTPEndpoint: "https://dl.gitea.io/gitea/version.json",
- }, func(ctx context.Context, _ *models.User, config Config) error {
+ }, func(ctx context.Context, _ *user_model.User, config Config) error {
updateCheckerConfig := config.(*UpdateCheckerConfig)
return updatechecker.GiteaUpdateChecker(updateCheckerConfig.HTTPEndpoint)
})