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.

cron.go 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2014 The Gogs 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. "time"
  7. "github.com/gogits/cron"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/log"
  10. "code.gitea.io/gitea/modules/setting"
  11. )
  12. var c = cron.New()
  13. func NewContext() {
  14. var (
  15. entry *cron.Entry
  16. err error
  17. )
  18. if setting.Cron.UpdateMirror.Enabled {
  19. entry, err = c.AddFunc("Update mirrors", setting.Cron.UpdateMirror.Schedule, models.MirrorUpdate)
  20. if err != nil {
  21. log.Fatal(4, "Cron[Update mirrors]: %v", err)
  22. }
  23. if setting.Cron.UpdateMirror.RunAtStart {
  24. entry.Prev = time.Now()
  25. entry.ExecTimes++
  26. go models.MirrorUpdate()
  27. }
  28. }
  29. if setting.Cron.RepoHealthCheck.Enabled {
  30. entry, err = c.AddFunc("Repository health check", setting.Cron.RepoHealthCheck.Schedule, models.GitFsck)
  31. if err != nil {
  32. log.Fatal(4, "Cron[Repository health check]: %v", err)
  33. }
  34. if setting.Cron.RepoHealthCheck.RunAtStart {
  35. entry.Prev = time.Now()
  36. entry.ExecTimes++
  37. go models.GitFsck()
  38. }
  39. }
  40. if setting.Cron.CheckRepoStats.Enabled {
  41. entry, err = c.AddFunc("Check repository statistics", setting.Cron.CheckRepoStats.Schedule, models.CheckRepoStats)
  42. if err != nil {
  43. log.Fatal(4, "Cron[Check repository statistics]: %v", err)
  44. }
  45. if setting.Cron.CheckRepoStats.RunAtStart {
  46. entry.Prev = time.Now()
  47. entry.ExecTimes++
  48. go models.CheckRepoStats()
  49. }
  50. }
  51. c.Start()
  52. }
  53. // ListTasks returns all running cron tasks.
  54. func ListTasks() []*cron.Entry {
  55. return c.Entries()
  56. }