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

tasks_basic.go 6.3 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. "code.gitea.io/gitea/modules/migrations"
  10. repository_service "code.gitea.io/gitea/modules/repository"
  11. "code.gitea.io/gitea/routers/repo"
  12. mirror_service "code.gitea.io/gitea/services/mirror"
  13. )
  14. func registerUpdateMirrorTask() {
  15. RegisterTaskFatal("update_mirrors", &BaseConfig{
  16. Enabled: true,
  17. RunAtStart: false,
  18. Schedule: "@every 10m",
  19. }, func(ctx context.Context, _ *models.User, _ Config) error {
  20. return mirror_service.Update(ctx)
  21. })
  22. }
  23. func registerRepoHealthCheck() {
  24. type RepoHealthCheckConfig struct {
  25. BaseConfig
  26. Timeout time.Duration
  27. Args []string `delim:" "`
  28. }
  29. RegisterTaskFatal("repo_health_check", &RepoHealthCheckConfig{
  30. BaseConfig: BaseConfig{
  31. Enabled: true,
  32. RunAtStart: false,
  33. Schedule: "@every 24h",
  34. },
  35. Timeout: 60 * time.Second,
  36. Args: []string{},
  37. }, func(ctx context.Context, _ *models.User, config Config) error {
  38. rhcConfig := config.(*RepoHealthCheckConfig)
  39. return repository_service.GitFsck(ctx, rhcConfig.Timeout, rhcConfig.Args)
  40. })
  41. }
  42. func registerCheckRepoStats() {
  43. RegisterTaskFatal("check_repo_stats", &BaseConfig{
  44. Enabled: true,
  45. RunAtStart: true,
  46. Schedule: "@every 24h",
  47. }, func(ctx context.Context, _ *models.User, _ Config) error {
  48. return models.CheckRepoStats(ctx)
  49. })
  50. }
  51. func registerArchiveCleanup() {
  52. RegisterTaskFatal("archive_cleanup", &OlderThanConfig{
  53. BaseConfig: BaseConfig{
  54. Enabled: true,
  55. RunAtStart: true,
  56. Schedule: "@every 24h",
  57. },
  58. OlderThan: 24 * time.Hour,
  59. }, func(ctx context.Context, _ *models.User, config Config) error {
  60. acConfig := config.(*OlderThanConfig)
  61. return models.DeleteOldRepositoryArchives(ctx, acConfig.OlderThan)
  62. })
  63. }
  64. func registerSyncExternalUsers() {
  65. RegisterTaskFatal("sync_external_users", &UpdateExistingConfig{
  66. BaseConfig: BaseConfig{
  67. Enabled: true,
  68. RunAtStart: false,
  69. Schedule: "@every 24h",
  70. },
  71. UpdateExisting: true,
  72. }, func(ctx context.Context, _ *models.User, config Config) error {
  73. realConfig := config.(*UpdateExistingConfig)
  74. return models.SyncExternalUsers(ctx, realConfig.UpdateExisting)
  75. })
  76. }
  77. func registerDeletedBranchesCleanup() {
  78. RegisterTaskFatal("deleted_branches_cleanup", &OlderThanConfig{
  79. BaseConfig: BaseConfig{
  80. Enabled: true,
  81. RunAtStart: true,
  82. Schedule: "@every 24h",
  83. },
  84. OlderThan: 24 * time.Hour,
  85. }, func(ctx context.Context, _ *models.User, config Config) error {
  86. realConfig := config.(*OlderThanConfig)
  87. models.RemoveOldDeletedBranches(ctx, realConfig.OlderThan)
  88. return nil
  89. })
  90. }
  91. func registerUpdateMigrationPosterID() {
  92. RegisterTaskFatal("update_migration_poster_id", &BaseConfig{
  93. Enabled: true,
  94. RunAtStart: true,
  95. Schedule: "@every 24h",
  96. }, func(ctx context.Context, _ *models.User, _ Config) error {
  97. return migrations.UpdateMigrationPosterID(ctx)
  98. })
  99. }
  100. func registerHandleUnDecompressAttachment() {
  101. RegisterTaskFatal("handle_undecompress_attachment", &BaseConfig{
  102. Enabled: true,
  103. RunAtStart: true,
  104. Schedule: "@every 10m",
  105. }, func(ctx context.Context, _ *models.User, _ Config) error {
  106. repo.HandleUnDecompressAttachment()
  107. return nil
  108. })
  109. }
  110. func registerHandleBlockChainUnSuccessUsers() {
  111. RegisterTaskFatal("handle_blockchain_unsuccess_users", &BaseConfig{
  112. Enabled: true,
  113. RunAtStart: true,
  114. Schedule: "@every 10m",
  115. }, func(ctx context.Context, _ *models.User, _ Config) error {
  116. repo.HandleBlockChainUnSuccessUsers()
  117. return nil
  118. })
  119. }
  120. func registerHandleBlockChainUnSuccessRepos() {
  121. RegisterTaskFatal("handle_blockchain_unsuccess_repos", &BaseConfig{
  122. Enabled: true,
  123. RunAtStart: true,
  124. Schedule: "@every 10m",
  125. }, func(ctx context.Context, _ *models.User, _ Config) error {
  126. repo.HandleBlockChainUnSuccessRepos()
  127. return nil
  128. })
  129. }
  130. func registerHandleBlockChainMergedPulls() {
  131. RegisterTaskFatal("handle_blockchain_merged_pull", &BaseConfig{
  132. Enabled: true,
  133. RunAtStart: true,
  134. Schedule: "@every 10m",
  135. }, func(ctx context.Context, _ *models.User, _ Config) error {
  136. repo.HandleBlockChainMergedPulls()
  137. return nil
  138. })
  139. }
  140. func registerHandleBlockChainUnSuccessCommits() {
  141. RegisterTaskFatal("handle_blockchain_unsuccess_commits", &BaseConfig{
  142. Enabled: true,
  143. RunAtStart: true,
  144. Schedule: "@every 10m",
  145. }, func(ctx context.Context, _ *models.User, _ Config) error {
  146. repo.HandleBlockChainUnSuccessCommits()
  147. return nil
  148. })
  149. }
  150. func registerHandleRepoAndUserStatistic() {
  151. RegisterTaskFatal("handle_repo_and_user_statistic", &BaseConfig{
  152. Enabled: true,
  153. RunAtStart: false,
  154. Schedule: "@daily",
  155. }, func(ctx context.Context, _ *models.User, _ Config) error {
  156. repo.StatisticAuto()
  157. return nil
  158. })
  159. }
  160. func registerHandleSummaryStatistic() {
  161. RegisterTaskFatal("handle_summary_statistic", &BaseConfig{
  162. Enabled: true,
  163. RunAtStart: false,
  164. Schedule: "@daily",
  165. }, func(ctx context.Context, _ *models.User, _ Config) error {
  166. repo.SummaryStatistic()
  167. return nil
  168. })
  169. }
  170. func registerHandleOrgStatistic() {
  171. RegisterTaskFatal("handle_org_statistic", &BaseConfig{
  172. Enabled: true,
  173. RunAtStart: false,
  174. Schedule: "0 0 2 * * ?",
  175. }, func(ctx context.Context, _ *models.User, _ Config) error {
  176. models.UpdateOrgStatistics()
  177. return nil
  178. })
  179. }
  180. func registerSyncCloudbrainStatus() {
  181. RegisterTaskFatal("sync_cloudbrain_status", &BaseConfig{
  182. Enabled: true,
  183. RunAtStart: false,
  184. Schedule: "@every 10m",
  185. }, func(ctx context.Context, _ *models.User, _ Config) error {
  186. repo.SyncCloudbrainStatus()
  187. return nil
  188. })
  189. }
  190. func initBasicTasks() {
  191. registerUpdateMirrorTask()
  192. registerRepoHealthCheck()
  193. registerCheckRepoStats()
  194. registerArchiveCleanup()
  195. registerSyncExternalUsers()
  196. registerDeletedBranchesCleanup()
  197. registerUpdateMigrationPosterID()
  198. registerHandleUnDecompressAttachment()
  199. registerHandleBlockChainUnSuccessUsers()
  200. registerHandleBlockChainUnSuccessRepos()
  201. registerHandleBlockChainMergedPulls()
  202. registerHandleBlockChainUnSuccessCommits()
  203. registerHandleRepoAndUserStatistic()
  204. registerHandleSummaryStatistic()
  205. registerSyncCloudbrainStatus()
  206. registerHandleOrgStatistic()
  207. }