2020-05-17 08:31:38 +09:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package cron
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2021-12-10 17:14:24 +09:00
|
|
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
2021-11-24 18:49:20 +09:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2020-05-17 08:31:38 +09:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2021-10-22 01:10:49 +09:00
|
|
|
"code.gitea.io/gitea/modules/updatechecker"
|
2021-11-16 22:30:11 +09:00
|
|
|
repo_service "code.gitea.io/gitea/services/repository"
|
2021-12-06 16:19:28 +09:00
|
|
|
archiver_service "code.gitea.io/gitea/services/repository/archiver"
|
2021-11-19 02:42:27 +09:00
|
|
|
user_service "code.gitea.io/gitea/services/user"
|
2020-05-17 08:31:38 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
func registerDeleteInactiveUsers() {
|
|
|
|
RegisterTaskFatal("delete_inactive_accounts", &OlderThanConfig{
|
|
|
|
BaseConfig: BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@annually",
|
|
|
|
},
|
|
|
|
OlderThan: 0 * time.Second,
|
2021-11-24 18:49:20 +09:00
|
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
2020-05-17 08:31:38 +09:00
|
|
|
olderThanConfig := config.(*OlderThanConfig)
|
2021-11-19 02:42:27 +09:00
|
|
|
return user_service.DeleteInactiveUsers(ctx, olderThanConfig.OlderThan)
|
2020-05-17 08:31:38 +09:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerDeleteRepositoryArchives() {
|
|
|
|
RegisterTaskFatal("delete_repo_archives", &BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@annually",
|
2021-11-24 18:49:20 +09:00
|
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
2021-12-06 16:19:28 +09:00
|
|
|
return archiver_service.DeleteRepositoryArchives(ctx)
|
2020-05-17 08:31:38 +09:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerGarbageCollectRepositories() {
|
|
|
|
type RepoHealthCheckConfig struct {
|
|
|
|
BaseConfig
|
|
|
|
Timeout time.Duration
|
|
|
|
Args []string `delim:" "`
|
|
|
|
}
|
|
|
|
RegisterTaskFatal("git_gc_repos", &RepoHealthCheckConfig{
|
|
|
|
BaseConfig: BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 72h",
|
|
|
|
},
|
|
|
|
Timeout: time.Duration(setting.Git.Timeout.GC) * time.Second,
|
|
|
|
Args: setting.Git.GCArgs,
|
2021-11-24 18:49:20 +09:00
|
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
2020-05-17 08:31:38 +09:00
|
|
|
rhcConfig := config.(*RepoHealthCheckConfig)
|
2021-11-24 16:56:24 +09:00
|
|
|
return repo_service.GitGcRepos(ctx, rhcConfig.Timeout, rhcConfig.Args...)
|
2020-05-17 08:31:38 +09:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerRewriteAllPublicKeys() {
|
|
|
|
RegisterTaskFatal("resync_all_sshkeys", &BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 72h",
|
2021-11-24 18:49:20 +09:00
|
|
|
}, func(_ context.Context, _ *user_model.User, _ Config) error {
|
2021-12-10 17:14:24 +09:00
|
|
|
return asymkey_model.RewriteAllPublicKeys()
|
2020-05-17 08:31:38 +09:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-10-11 09:38:09 +09:00
|
|
|
func registerRewriteAllPrincipalKeys() {
|
|
|
|
RegisterTaskFatal("resync_all_sshprincipals", &BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 72h",
|
2021-11-24 18:49:20 +09:00
|
|
|
}, func(_ context.Context, _ *user_model.User, _ Config) error {
|
2021-12-10 17:14:24 +09:00
|
|
|
return asymkey_model.RewriteAllPrincipalKeys()
|
2020-10-11 09:38:09 +09:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-17 08:31:38 +09:00
|
|
|
func registerRepositoryUpdateHook() {
|
|
|
|
RegisterTaskFatal("resync_all_hooks", &BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 72h",
|
2021-11-24 18:49:20 +09:00
|
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
2021-11-18 00:17:31 +09:00
|
|
|
return repo_service.SyncRepositoryHooks(ctx)
|
2020-05-17 08:31:38 +09:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerReinitMissingRepositories() {
|
|
|
|
RegisterTaskFatal("reinit_missing_repos", &BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 72h",
|
2021-11-24 18:49:20 +09:00
|
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
2021-11-24 16:56:24 +09:00
|
|
|
return repo_service.ReinitMissingRepositories(ctx)
|
2020-05-17 08:31:38 +09:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerDeleteMissingRepositories() {
|
|
|
|
RegisterTaskFatal("delete_missing_repos", &BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 72h",
|
2021-11-24 18:49:20 +09:00
|
|
|
}, func(ctx context.Context, user *user_model.User, _ Config) error {
|
2021-11-24 16:56:24 +09:00
|
|
|
return repo_service.DeleteMissingRepositories(ctx, user)
|
2020-05-17 08:31:38 +09:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerRemoveRandomAvatars() {
|
|
|
|
RegisterTaskFatal("delete_generated_repository_avatars", &BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 72h",
|
2021-11-24 18:49:20 +09:00
|
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
2021-12-13 00:48:20 +09:00
|
|
|
return repo_service.RemoveRandomAvatars(ctx)
|
2020-05-17 08:31:38 +09:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-01 21:17:02 +09:00
|
|
|
func registerDeleteOldActions() {
|
|
|
|
RegisterTaskFatal("delete_old_actions", &OlderThanConfig{
|
|
|
|
BaseConfig: BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 168h",
|
|
|
|
},
|
|
|
|
OlderThan: 365 * 24 * time.Hour,
|
2021-11-24 18:49:20 +09:00
|
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
2021-05-01 21:17:02 +09:00
|
|
|
olderThanConfig := config.(*OlderThanConfig)
|
|
|
|
return models.DeleteOldActions(olderThanConfig.OlderThan)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-10-16 15:14:34 +09:00
|
|
|
func registerUpdateGiteaChecker() {
|
|
|
|
type UpdateCheckerConfig struct {
|
|
|
|
BaseConfig
|
|
|
|
HTTPEndpoint string
|
|
|
|
}
|
|
|
|
RegisterTaskFatal("update_checker", &UpdateCheckerConfig{
|
|
|
|
BaseConfig: BaseConfig{
|
|
|
|
Enabled: true,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 168h",
|
|
|
|
},
|
|
|
|
HTTPEndpoint: "https://dl.gitea.io/gitea/version.json",
|
2021-11-24 18:49:20 +09:00
|
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
2021-10-16 15:14:34 +09:00
|
|
|
updateCheckerConfig := config.(*UpdateCheckerConfig)
|
2021-10-22 01:10:49 +09:00
|
|
|
return updatechecker.GiteaUpdateChecker(updateCheckerConfig.HTTPEndpoint)
|
2021-10-16 15:14:34 +09:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-17 08:31:38 +09:00
|
|
|
func initExtendedTasks() {
|
|
|
|
registerDeleteInactiveUsers()
|
|
|
|
registerDeleteRepositoryArchives()
|
|
|
|
registerGarbageCollectRepositories()
|
|
|
|
registerRewriteAllPublicKeys()
|
2020-10-11 09:38:09 +09:00
|
|
|
registerRewriteAllPrincipalKeys()
|
2020-05-17 08:31:38 +09:00
|
|
|
registerRepositoryUpdateHook()
|
|
|
|
registerReinitMissingRepositories()
|
|
|
|
registerDeleteMissingRepositories()
|
|
|
|
registerRemoveRandomAvatars()
|
2021-05-01 21:17:02 +09:00
|
|
|
registerDeleteOldActions()
|
2021-10-16 15:14:34 +09:00
|
|
|
registerUpdateGiteaChecker()
|
2020-05-17 08:31:38 +09:00
|
|
|
}
|