You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
3.3 KiB

  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package cron
  5. import (
  6. "context"
  7. "time"
  8. "code.gitea.io/gitea/models"
  9. repo_module "code.gitea.io/gitea/modules/repository"
  10. "code.gitea.io/gitea/modules/setting"
  11. )
  12. func registerDeleteInactiveUsers() {
  13. RegisterTaskFatal("delete_inactive_accounts", &OlderThanConfig{
  14. BaseConfig: BaseConfig{
  15. Enabled: false,
  16. RunAtStart: false,
  17. Schedule: "@annually",
  18. },
  19. OlderThan: 0 * time.Second,
  20. }, func(ctx context.Context, _ *models.User, config Config) error {
  21. olderThanConfig := config.(*OlderThanConfig)
  22. return models.DeleteInactiveUsers(ctx, olderThanConfig.OlderThan)
  23. })
  24. }
  25. func registerDeleteRepositoryArchives() {
  26. RegisterTaskFatal("delete_repo_archives", &BaseConfig{
  27. Enabled: false,
  28. RunAtStart: false,
  29. Schedule: "@annually",
  30. }, func(ctx context.Context, _ *models.User, _ Config) error {
  31. return models.DeleteRepositoryArchives(ctx)
  32. })
  33. }
  34. func registerGarbageCollectRepositories() {
  35. type RepoHealthCheckConfig struct {
  36. BaseConfig
  37. Timeout time.Duration
  38. Args []string `delim:" "`
  39. }
  40. RegisterTaskFatal("git_gc_repos", &RepoHealthCheckConfig{
  41. BaseConfig: BaseConfig{
  42. Enabled: false,
  43. RunAtStart: false,
  44. Schedule: "@every 72h",
  45. },
  46. Timeout: time.Duration(setting.Git.Timeout.GC) * time.Second,
  47. Args: setting.Git.GCArgs,
  48. }, func(ctx context.Context, _ *models.User, config Config) error {
  49. rhcConfig := config.(*RepoHealthCheckConfig)
  50. return repo_module.GitGcRepos(ctx, rhcConfig.Timeout, rhcConfig.Args...)
  51. })
  52. }
  53. func registerRewriteAllPublicKeys() {
  54. RegisterTaskFatal("resync_all_sshkeys", &BaseConfig{
  55. Enabled: false,
  56. RunAtStart: false,
  57. Schedule: "@every 72h",
  58. }, func(_ context.Context, _ *models.User, _ Config) error {
  59. return models.RewriteAllPublicKeys()
  60. })
  61. }
  62. func registerRepositoryUpdateHook() {
  63. RegisterTaskFatal("resync_all_hooks", &BaseConfig{
  64. Enabled: false,
  65. RunAtStart: false,
  66. Schedule: "@every 72h",
  67. }, func(ctx context.Context, _ *models.User, _ Config) error {
  68. return repo_module.SyncRepositoryHooks(ctx)
  69. })
  70. }
  71. func registerReinitMissingRepositories() {
  72. RegisterTaskFatal("reinit_missing_repos", &BaseConfig{
  73. Enabled: false,
  74. RunAtStart: false,
  75. Schedule: "@every 72h",
  76. }, func(ctx context.Context, _ *models.User, _ Config) error {
  77. return repo_module.ReinitMissingRepositories(ctx)
  78. })
  79. }
  80. func registerDeleteMissingRepositories() {
  81. RegisterTaskFatal("delete_missing_repos", &BaseConfig{
  82. Enabled: false,
  83. RunAtStart: false,
  84. Schedule: "@every 72h",
  85. }, func(ctx context.Context, user *models.User, _ Config) error {
  86. return repo_module.DeleteMissingRepositories(ctx, user)
  87. })
  88. }
  89. func registerRemoveRandomAvatars() {
  90. RegisterTaskFatal("delete_generated_repository_avatars", &BaseConfig{
  91. Enabled: false,
  92. RunAtStart: false,
  93. Schedule: "@every 72h",
  94. }, func(ctx context.Context, _ *models.User, _ Config) error {
  95. return models.RemoveRandomAvatars(ctx)
  96. })
  97. }
  98. func initExtendedTasks() {
  99. registerDeleteInactiveUsers()
  100. registerDeleteRepositoryArchives()
  101. registerGarbageCollectRepositories()
  102. registerRewriteAllPublicKeys()
  103. registerRepositoryUpdateHook()
  104. registerReinitMissingRepositories()
  105. registerDeleteMissingRepositories()
  106. registerRemoveRandomAvatars()
  107. }