make cron task configurable

tokarchuk/v1.17
Unknwon 9 years ago
parent d17f102339
commit b1696665bd
  1. 31
      conf/app.ini
  2. 2
      gogs.go
  3. 40
      models/cron/cron.go
  4. 8
      models/repo.go
  5. 60
      modules/bindata/bindata.go
  6. 27
      modules/cron/manager.go
  7. 27
      modules/setting/setting.go
  8. 4
      routers/admin/admin.go
  9. 2
      routers/install.go
  10. 2
      templates/.VERSION

@ -281,21 +281,34 @@ DRIVER =
; Based on xorm, e.g.: root:root@localhost/gogs?charset=utf8
CONN =
[cron]
; Enable running cron tasks periodically.
ENABLED = true
; Run cron tasks when Gogs starts.
RUN_AT_START = false
; Update mirrors
[cron.update_mirrors]
SCHEDULE = @every 1h
; Repository health check
[cron.repo_health_check]
SCHEDULE = @every 24h
; Arguments for command 'git fsck', e.g.: "--unreachable --tags"
; see more on http://git-scm.com/docs/git-fsck/1.7.5
ARGS =
; Check repository statistics
[cron.check_repo_stats]
RUN_AT_START = true
SCHEDULE = @every 24h
[git]
MAX_GIT_DIFF_LINES = 10000
; Arguments for command 'git gc', e.g.: "--aggressive --auto"
; see more on http://git-scm.com/docs/git-gc/1.7.5
GC_ARGS =
; Git health check.
[git.fsck]
ENABLE = true
; Execution interval in hours. Default is 24.
INTERVAL = 24
; Arguments for command 'git fsck', e.g.: "--unreachable --tags"
; see more on http://git-scm.com/docs/git-fsck/1.7.5
ARGS =
[i18n]
LANGS = en-US,zh-CN,zh-HK,de-DE,fr-FR,nl-NL,lv-LV,ru-RU,ja-JP,es-ES,pt-BR,pl-PL,bg-BG,it-IT
NAMES = English,简体中文,繁體中文,Deutsch,Français,Nederlands,Latviešu,Русский,日本語,Español,Português do Brasil,Polski,български,Italiano

@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting"
)
const APP_VER = "0.6.5.0817 Beta"
const APP_VER = "0.6.5.0818 Beta"
func init() {
runtime.GOMAXPROCS(runtime.NumCPU())

@ -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()
}

@ -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 {

File diff suppressed because one or more lines are too long

@ -1,27 +0,0 @@
// 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 (
"fmt"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/setting"
)
var c = New()
func NewCronContext() {
c.AddFunc("Update mirrors", "@every 1h", models.MirrorUpdate)
if setting.Git.Fsck.Enable {
c.AddFunc("Repository health check", fmt.Sprintf("@every %dh", setting.Git.Fsck.Interval), models.GitFsck)
}
c.AddFunc("Check repository statistics", "@every 24h", models.CheckRepoStats)
c.Start()
}
func ListEntries() []*Entry {
return c.Entries()
}

@ -126,11 +126,26 @@ var (
Git struct {
MaxGitDiffLines int
GcArgs []string `delim:" "`
Fsck struct {
Enable bool
Interval int
Args []string `delim:" "`
} `ini:"git.fsck"`
}
// Cron tasks.
Cron struct {
UpdateMirror struct {
Enabled bool
RunAtStart bool
Schedule string
} `ini:"cron.update_mirrors"`
RepoHealthCheck struct {
Enabled bool
RunAtStart bool
Schedule string
Args []string `delim:" "`
} `ini:"cron.repo_health_check"`
CheckRepoStats struct {
Enabled bool
RunAtStart bool
Schedule string
} `ini:"cron.check_repo_stats"`
}
// I18n settings.
@ -361,6 +376,8 @@ func NewConfigContext() {
if err = Cfg.Section("git").MapTo(&Git); err != nil {
log.Fatal(4, "Fail to map Git settings: %v", err)
} else if Cfg.Section("cron").MapTo(&Cron); err != nil {
log.Fatal(4, "Fail to map Cron settings: %v", err)
}
Langs = Cfg.Section("i18n").Key("LANGS").Strings(",")

@ -14,8 +14,8 @@ import (
"github.com/Unknwon/macaron"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/models/cron"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/cron"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/process"
"github.com/gogits/gogs/modules/setting"
@ -229,6 +229,6 @@ func Monitor(ctx *middleware.Context) {
ctx.Data["PageIsAdmin"] = true
ctx.Data["PageIsAdminMonitor"] = true
ctx.Data["Processes"] = process.Processes
ctx.Data["Entries"] = cron.ListEntries()
ctx.Data["Entries"] = cron.ListTasks()
ctx.HTML(200, MONITOR)
}

@ -18,9 +18,9 @@ import (
"gopkg.in/ini.v1"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/models/cron"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/cron"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware"

@ -1 +1 @@
0.6.5.0817 Beta
0.6.5.0818 Beta
Loading…
Cancel
Save