summaryrefslogtreecommitdiffstats
path: root/models
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
parentd17f102339c8542cfb5e81ab6a705b1b64651f51 (diff)
downloadgitea-b1696665bdf0e31c227493cf637d3867e102d131.tar.gz
gitea-b1696665bdf0e31c227493cf637d3867e102d131.zip
make cron task configurable
Diffstat (limited to 'models')
-rw-r--r--models/cron/cron.go40
-rw-r--r--models/repo.go8
2 files changed, 44 insertions, 4 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()
+}
diff --git a/models/repo.go b/models/repo.go
index fb787baeac..c4304d9bee 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -1108,7 +1108,7 @@ func RewriteRepositoryUpdateHook() error {
}
var (
- // Prevent duplicate tasks.
+ // Prevent duplicate running tasks.
isMirrorUpdating = false
isGitFscking = false
isCheckingRepos = false
@@ -1164,7 +1164,7 @@ func GitFsck() {
isGitFscking = true
defer func() { isGitFscking = false }()
- args := append([]string{"fsck"}, setting.Git.Fsck.Args...)
+ args := append([]string{"fsck"}, setting.Cron.RepoHealthCheck.Args...)
if err := x.Where("id > 0").Iterate(new(Repository),
func(idx int, bean interface{}) error {
repo := bean.(*Repository)
@@ -1216,7 +1216,7 @@ func CheckRepoStats() {
log.Error(4, "select repository check 'watch': %v", err)
}
for _, repo_id := range results_watch {
- log.Info("updating repository count 'watch'")
+ log.Trace("updating repository count 'watch'")
repoID := com.StrTo(repo_id["id"]).MustInt64()
_, err := x.Exec("UPDATE `repository` SET num_watches=(SELECT count(*) FROM `watch` WHERE repo_id=?) WHERE id=?", repoID, repoID)
if err != nil {
@@ -1230,7 +1230,7 @@ func CheckRepoStats() {
log.Error(4, "select repository check 'star': %v", err)
}
for _, repo_id := range results_star {
- log.Info("updating repository count 'star'")
+ log.Trace("updating repository count 'star'")
repoID := com.StrTo(repo_id["id"]).MustInt64()
_, err := x.Exec("UPDATE `repository` SET .num_stars=(SELECT count(*) FROM `star` WHERE repo_id=?) WHERE id=?", repoID, repoID)
if err != nil {