2020-05-17 05:01:38 +05:30
|
|
|
// 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"
|
|
|
|
repo_module "code.gitea.io/gitea/modules/repository"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2021-10-21 21:40:49 +05:30
|
|
|
"code.gitea.io/gitea/modules/updatechecker"
|
2021-11-16 19:00:11 +05:30
|
|
|
repo_service "code.gitea.io/gitea/services/repository"
|
2020-05-17 05:01:38 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
func registerDeleteInactiveUsers() {
|
|
|
|
RegisterTaskFatal("delete_inactive_accounts", &OlderThanConfig{
|
|
|
|
BaseConfig: BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@annually",
|
|
|
|
},
|
|
|
|
OlderThan: 0 * time.Second,
|
|
|
|
}, func(ctx context.Context, _ *models.User, config Config) error {
|
|
|
|
olderThanConfig := config.(*OlderThanConfig)
|
|
|
|
return models.DeleteInactiveUsers(ctx, olderThanConfig.OlderThan)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerDeleteRepositoryArchives() {
|
|
|
|
RegisterTaskFatal("delete_repo_archives", &BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@annually",
|
|
|
|
}, func(ctx context.Context, _ *models.User, _ Config) error {
|
2021-11-16 19:00:11 +05:30
|
|
|
return repo_service.DeleteRepositoryArchives(ctx)
|
2020-05-17 05:01:38 +05:30
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
}, func(ctx context.Context, _ *models.User, config Config) error {
|
|
|
|
rhcConfig := config.(*RepoHealthCheckConfig)
|
|
|
|
return repo_module.GitGcRepos(ctx, rhcConfig.Timeout, rhcConfig.Args...)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerRewriteAllPublicKeys() {
|
|
|
|
RegisterTaskFatal("resync_all_sshkeys", &BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 72h",
|
|
|
|
}, func(_ context.Context, _ *models.User, _ Config) error {
|
|
|
|
return models.RewriteAllPublicKeys()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-10-11 06:08:09 +05:30
|
|
|
func registerRewriteAllPrincipalKeys() {
|
|
|
|
RegisterTaskFatal("resync_all_sshprincipals", &BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 72h",
|
|
|
|
}, func(_ context.Context, _ *models.User, _ Config) error {
|
|
|
|
return models.RewriteAllPrincipalKeys()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-17 05:01:38 +05:30
|
|
|
func registerRepositoryUpdateHook() {
|
|
|
|
RegisterTaskFatal("resync_all_hooks", &BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 72h",
|
|
|
|
}, func(ctx context.Context, _ *models.User, _ Config) error {
|
|
|
|
return repo_module.SyncRepositoryHooks(ctx)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerReinitMissingRepositories() {
|
|
|
|
RegisterTaskFatal("reinit_missing_repos", &BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 72h",
|
|
|
|
}, func(ctx context.Context, _ *models.User, _ Config) error {
|
|
|
|
return repo_module.ReinitMissingRepositories(ctx)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerDeleteMissingRepositories() {
|
|
|
|
RegisterTaskFatal("delete_missing_repos", &BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 72h",
|
|
|
|
}, func(ctx context.Context, user *models.User, _ Config) error {
|
|
|
|
return repo_module.DeleteMissingRepositories(ctx, user)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func registerRemoveRandomAvatars() {
|
|
|
|
RegisterTaskFatal("delete_generated_repository_avatars", &BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 72h",
|
|
|
|
}, func(ctx context.Context, _ *models.User, _ Config) error {
|
|
|
|
return models.RemoveRandomAvatars(ctx)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-05-01 17:47:02 +05:30
|
|
|
func registerDeleteOldActions() {
|
|
|
|
RegisterTaskFatal("delete_old_actions", &OlderThanConfig{
|
|
|
|
BaseConfig: BaseConfig{
|
|
|
|
Enabled: false,
|
|
|
|
RunAtStart: false,
|
|
|
|
Schedule: "@every 168h",
|
|
|
|
},
|
|
|
|
OlderThan: 365 * 24 * time.Hour,
|
|
|
|
}, func(ctx context.Context, _ *models.User, config Config) error {
|
|
|
|
olderThanConfig := config.(*OlderThanConfig)
|
|
|
|
return models.DeleteOldActions(olderThanConfig.OlderThan)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-10-16 11:44:34 +05:30
|
|
|
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",
|
|
|
|
}, func(ctx context.Context, _ *models.User, config Config) error {
|
|
|
|
updateCheckerConfig := config.(*UpdateCheckerConfig)
|
2021-10-21 21:40:49 +05:30
|
|
|
return updatechecker.GiteaUpdateChecker(updateCheckerConfig.HTTPEndpoint)
|
2021-10-16 11:44:34 +05:30
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-05-17 05:01:38 +05:30
|
|
|
func initExtendedTasks() {
|
|
|
|
registerDeleteInactiveUsers()
|
|
|
|
registerDeleteRepositoryArchives()
|
|
|
|
registerGarbageCollectRepositories()
|
|
|
|
registerRewriteAllPublicKeys()
|
2020-10-11 06:08:09 +05:30
|
|
|
registerRewriteAllPrincipalKeys()
|
2020-05-17 05:01:38 +05:30
|
|
|
registerRepositoryUpdateHook()
|
|
|
|
registerReinitMissingRepositories()
|
|
|
|
registerDeleteMissingRepositories()
|
|
|
|
registerRemoveRandomAvatars()
|
2021-05-01 17:47:02 +05:30
|
|
|
registerDeleteOldActions()
|
2021-10-16 11:44:34 +05:30
|
|
|
registerUpdateGiteaChecker()
|
2020-05-17 05:01:38 +05:30
|
|
|
}
|