summaryrefslogtreecommitdiffstats
path: root/models/cron
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-08-18 02:19:29 +0800
committerUnknwon <u@gogs.io>2015-08-18 02:19:29 +0800
commitb1696665bdf0e31c227493cf637d3867e102d131 (patch)
tree4dbd11c8998a8875147cf8e23b3d819d5aee080e /models/cron
parentd17f102339c8542cfb5e81ab6a705b1b64651f51 (diff)
downloadgitea-b1696665bdf0e31c227493cf637d3867e102d131.tar.gz
gitea-b1696665bdf0e31c227493cf637d3867e102d131.zip
make cron task configurable
Diffstat (limited to 'models/cron')
-rw-r--r--models/cron/cron.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/models/cron/cron.go b/models/cron/cron.go
new file mode 100644
index 0000000000..348f5ce53b
--- /dev/null
+++ b/models/cron/cron.go
@@ -0,0 +1,40 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package cron
+
+import (
+ "github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/modules/cron"
+ "github.com/gogits/gogs/modules/setting"
+)
+
+var c = cron.New()
+
+func NewCronContext() {
+ if setting.Cron.UpdateMirror.Enabled {
+ c.AddFunc("Update mirrors", setting.Cron.UpdateMirror.Schedule, models.MirrorUpdate)
+ if setting.Cron.UpdateMirror.RunAtStart {
+ go models.MirrorUpdate()
+ }
+ }
+ if setting.Cron.RepoHealthCheck.Enabled {
+ c.AddFunc("Repository health check", setting.Cron.RepoHealthCheck.Schedule, models.GitFsck)
+ if setting.Cron.RepoHealthCheck.RunAtStart {
+ go models.GitFsck()
+ }
+ }
+ if setting.Cron.CheckRepoStats.Enabled {
+ c.AddFunc("Check repository statistics", setting.Cron.CheckRepoStats.Schedule, models.CheckRepoStats)
+ if setting.Cron.CheckRepoStats.RunAtStart {
+ go models.CheckRepoStats()
+ }
+ }
+ c.Start()
+}
+
+// ListTasks returns all running cron tasks.
+func ListTasks() []*cron.Entry {
+ return c.Entries()
+}