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 7.0 kB

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