mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-25 15:53:36 +01:00
c53f802778
- This is being disabled as it will weekly connect to a domain. - This only affects existing installations, as new installations will have a explicit value being written into app.ini due to https://github.com/go-gitea/gitea/pull/21655 (cherry picked from commitcd0b8b6852
) (cherry picked from commit58d43867ca
) (cherry picked from commitf290b91e50
) (cherry picked from commit5bd6d75554
) (cherry picked from commite5d0abb592
) (cherry picked from commit4b381ce77e
) (cherry picked from commitb6a9b1390d
) (cherry picked from commit3674362871
) (cherry picked from commitaf0f606fc1
) (cherry picked from commit49560da6fb
) (cherry picked from commitca06e27c5b
) (cherry picked from commit163df86df5
) (cherry picked from commit0391c6ae42
) (cherry picked from commitf282f2d42f
) (cherry picked from commit68d31cf247
) (cherry picked from commitcfd4a479e9
) (cherry picked from commitadd969bdf6
) (cherry picked from commitc0f3f1f1e7
) (cherry picked from commitf11dca9090
) (cherry picked from commit283810387f
) (cherry picked from commit08af1f0ea8
) (cherry picked from commit1c1a6da319
) (cherry picked from commitc1444bae65
) (cherry picked from commit6361df634b
) (cherry picked from commitcc8bb3f946
) (cherry picked from commitc7ae4411fd
) (cherry picked from commitf73f4eef02
) (cherry picked from commit2122896e85
) (cherry picked from commitd469c99671
) (cherry picked from commit41dbbd731e
) (cherry picked from commite8e742b437
) (cherry picked from commit0fa9f87b5f
) (cherry picked from commita92c724a56
) (cherry picked from commit6a18d153e1
) (cherry picked from commit0dd35a13fd
) (cherry picked from commit5ae0cbe0ae
) (cherry picked from commit13bd3cf37b
) (cherry picked from commita163efa6cf
) (cherry picked from commit422a6e8329
) (cherry picked from commit125fb33e1b
) (cherry picked from commitfd39d15a92
) (cherry picked from commitb581474513
) (cherry picked from commit987d198523
) (cherry picked from commitf06eed025f
) (cherry picked from commit6f9f415644
) (cherry picked from commiteb2c878deb
) (cherry picked from commit70daffa9fe
) (cherry picked from commit3a6ae6fa49
) (cherry picked from commit682a564b04
)
241 lines
7.6 KiB
Go
241 lines
7.6 KiB
Go
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cron
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
activities_model "code.gitea.io/gitea/models/activities"
|
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
|
"code.gitea.io/gitea/models/system"
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
"code.gitea.io/gitea/modules/git"
|
|
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
"code.gitea.io/gitea/modules/updatechecker"
|
|
repo_service "code.gitea.io/gitea/services/repository"
|
|
archiver_service "code.gitea.io/gitea/services/repository/archiver"
|
|
user_service "code.gitea.io/gitea/services/user"
|
|
)
|
|
|
|
func registerDeleteInactiveUsers() {
|
|
RegisterTaskFatal("delete_inactive_accounts", &OlderThanConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@annually",
|
|
},
|
|
OlderThan: time.Minute * time.Duration(setting.Service.ActiveCodeLives),
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
olderThanConfig := config.(*OlderThanConfig)
|
|
return user_service.DeleteInactiveUsers(ctx, olderThanConfig.OlderThan)
|
|
})
|
|
}
|
|
|
|
func registerDeleteRepositoryArchives() {
|
|
RegisterTaskFatal("delete_repo_archives", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@annually",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return archiver_service.DeleteRepositoryArchives(ctx)
|
|
})
|
|
}
|
|
|
|
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, _ *user_model.User, config Config) error {
|
|
rhcConfig := config.(*RepoHealthCheckConfig)
|
|
// the git args are set by config, they can be safe to be trusted
|
|
return repo_service.GitGcRepos(ctx, rhcConfig.Timeout, git.ToTrustedCmdArgs(rhcConfig.Args))
|
|
})
|
|
}
|
|
|
|
func registerRewriteAllPublicKeys() {
|
|
RegisterTaskFatal("resync_all_sshkeys", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return asymkey_model.RewriteAllPublicKeys(ctx)
|
|
})
|
|
}
|
|
|
|
func registerRewriteAllPrincipalKeys() {
|
|
RegisterTaskFatal("resync_all_sshprincipals", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return asymkey_model.RewriteAllPrincipalKeys(ctx)
|
|
})
|
|
}
|
|
|
|
func registerRepositoryUpdateHook() {
|
|
RegisterTaskFatal("resync_all_hooks", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return repo_service.SyncRepositoryHooks(ctx)
|
|
})
|
|
}
|
|
|
|
func registerReinitMissingRepositories() {
|
|
RegisterTaskFatal("reinit_missing_repos", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return repo_service.ReinitMissingRepositories(ctx)
|
|
})
|
|
}
|
|
|
|
func registerDeleteMissingRepositories() {
|
|
RegisterTaskFatal("delete_missing_repos", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, user *user_model.User, _ Config) error {
|
|
return repo_service.DeleteMissingRepositories(ctx, user)
|
|
})
|
|
}
|
|
|
|
func registerRemoveRandomAvatars() {
|
|
RegisterTaskFatal("delete_generated_repository_avatars", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 72h",
|
|
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
|
|
return repo_service.RemoveRandomAvatars(ctx)
|
|
})
|
|
}
|
|
|
|
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, _ *user_model.User, config Config) error {
|
|
olderThanConfig := config.(*OlderThanConfig)
|
|
return activities_model.DeleteOldActions(ctx, olderThanConfig.OlderThan)
|
|
})
|
|
}
|
|
|
|
func registerUpdateGiteaChecker() {
|
|
type UpdateCheckerConfig struct {
|
|
BaseConfig
|
|
HTTPEndpoint string
|
|
}
|
|
RegisterTaskFatal("update_checker", &UpdateCheckerConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 168h",
|
|
},
|
|
HTTPEndpoint: "https://dl.gitea.com/gitea/version.json",
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
updateCheckerConfig := config.(*UpdateCheckerConfig)
|
|
return updatechecker.GiteaUpdateChecker(updateCheckerConfig.HTTPEndpoint)
|
|
})
|
|
}
|
|
|
|
func registerDeleteOldSystemNotices() {
|
|
RegisterTaskFatal("delete_old_system_notices", &OlderThanConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 168h",
|
|
},
|
|
OlderThan: 365 * 24 * time.Hour,
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
olderThanConfig := config.(*OlderThanConfig)
|
|
return system.DeleteOldSystemNotices(ctx, olderThanConfig.OlderThan)
|
|
})
|
|
}
|
|
|
|
func registerGCLFS() {
|
|
if !setting.LFS.StartServer {
|
|
return
|
|
}
|
|
type GCLFSConfig struct {
|
|
OlderThanConfig
|
|
LastUpdatedMoreThanAgo time.Duration
|
|
NumberToCheckPerRepo int64
|
|
ProportionToCheckPerRepo float64
|
|
}
|
|
|
|
RegisterTaskFatal("gc_lfs", &GCLFSConfig{
|
|
OlderThanConfig: OlderThanConfig{
|
|
BaseConfig: BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@every 24h",
|
|
},
|
|
// Only attempt to garbage collect lfs meta objects older than a week as the order of git lfs upload
|
|
// and git object upload is not necessarily guaranteed. It's possible to imagine a situation whereby
|
|
// an LFS object is uploaded but the git branch is not uploaded immediately, or there are some rapid
|
|
// changes in new branches that might lead to lfs objects becoming temporarily unassociated with git
|
|
// objects.
|
|
//
|
|
// It is likely that a week is potentially excessive but it should definitely be enough that any
|
|
// unassociated LFS object is genuinely unassociated.
|
|
OlderThan: 24 * time.Hour * 7,
|
|
},
|
|
// Only GC things that haven't been looked at in the past 3 days
|
|
LastUpdatedMoreThanAgo: 24 * time.Hour * 3,
|
|
NumberToCheckPerRepo: 100,
|
|
ProportionToCheckPerRepo: 0.6,
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
gcLFSConfig := config.(*GCLFSConfig)
|
|
return repo_service.GarbageCollectLFSMetaObjects(ctx, repo_service.GarbageCollectLFSMetaObjectsOptions{
|
|
AutoFix: true,
|
|
OlderThan: time.Now().Add(-gcLFSConfig.OlderThan),
|
|
UpdatedLessRecentlyThan: time.Now().Add(-gcLFSConfig.LastUpdatedMoreThanAgo),
|
|
})
|
|
})
|
|
}
|
|
|
|
func registerRebuildIssueIndexer() {
|
|
RegisterTaskFatal("rebuild_issue_indexer", &BaseConfig{
|
|
Enabled: false,
|
|
RunAtStart: false,
|
|
Schedule: "@annually",
|
|
}, func(ctx context.Context, _ *user_model.User, config Config) error {
|
|
return issue_indexer.PopulateIssueIndexer(ctx)
|
|
})
|
|
}
|
|
|
|
func initExtendedTasks() {
|
|
registerDeleteInactiveUsers()
|
|
registerDeleteRepositoryArchives()
|
|
registerGarbageCollectRepositories()
|
|
registerRewriteAllPublicKeys()
|
|
registerRewriteAllPrincipalKeys()
|
|
registerRepositoryUpdateHook()
|
|
registerReinitMissingRepositories()
|
|
registerDeleteMissingRepositories()
|
|
registerRemoveRandomAvatars()
|
|
registerDeleteOldActions()
|
|
registerUpdateGiteaChecker()
|
|
registerDeleteOldSystemNotices()
|
|
registerGCLFS()
|
|
registerRebuildIssueIndexer()
|
|
}
|