Browse Source

make cron task configurable

tags/v0.9.99
Unknwon 8 years ago
parent
commit
b1696665bd
10 changed files with 123 additions and 80 deletions
  1. 22
    9
      conf/app.ini
  2. 1
    1
      gogs.go
  3. 40
    0
      models/cron/cron.go
  4. 4
    4
      models/repo.go
  5. 30
    30
      modules/bindata/bindata.go
  6. 0
    27
      modules/cron/manager.go
  7. 22
    5
      modules/setting/setting.go
  8. 2
    2
      routers/admin/admin.go
  9. 1
    1
      routers/install.go
  10. 1
    1
      templates/.VERSION

+ 22
- 9
conf/app.ini View File

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

+ 1
- 1
gogs.go View File

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

+ 40
- 0
models/cron/cron.go View File

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

+ 4
- 4
models/repo.go View File

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

+ 30
- 30
modules/bindata/bindata.go
File diff suppressed because it is too large
View File


+ 0
- 27
modules/cron/manager.go View File

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

+ 22
- 5
modules/setting/setting.go View File

@@ -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(",")

+ 2
- 2
routers/admin/admin.go View File

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

+ 1
- 1
routers/install.go View File

@@ -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
templates/.VERSION View File

@@ -1 +1 @@
0.6.5.0817 Beta
0.6.5.0818 Beta

Loading…
Cancel
Save