cron.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. "github.com/gogits/gogs/models"
  7. "github.com/gogits/gogs/modules/cron"
  8. "github.com/gogits/gogs/modules/setting"
  9. )
  10. var c = cron.New()
  11. func NewCronContext() {
  12. if setting.Cron.UpdateMirror.Enabled {
  13. c.AddFunc("Update mirrors", setting.Cron.UpdateMirror.Schedule, models.MirrorUpdate)
  14. if setting.Cron.UpdateMirror.RunAtStart {
  15. go models.MirrorUpdate()
  16. }
  17. }
  18. if setting.Cron.RepoHealthCheck.Enabled {
  19. c.AddFunc("Repository health check", setting.Cron.RepoHealthCheck.Schedule, models.GitFsck)
  20. if setting.Cron.RepoHealthCheck.RunAtStart {
  21. go models.GitFsck()
  22. }
  23. }
  24. if setting.Cron.CheckRepoStats.Enabled {
  25. c.AddFunc("Check repository statistics", setting.Cron.CheckRepoStats.Schedule, models.CheckRepoStats)
  26. if setting.Cron.CheckRepoStats.RunAtStart {
  27. go models.CheckRepoStats()
  28. }
  29. }
  30. c.Start()
  31. }
  32. // ListTasks returns all running cron tasks.
  33. func ListTasks() []*cron.Entry {
  34. return c.Entries()
  35. }