bench-forgejo/models/cron/cron.go

60 lines
1.5 KiB
Go
Raw Normal View History

2015-08-17 23:49:29 +05:30
// 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 (
2015-08-18 01:33:11 +05:30
"time"
2015-08-17 23:49:29 +05:30
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/cron"
2015-08-18 01:33:11 +05:30
"github.com/gogits/gogs/modules/log"
2015-08-17 23:49:29 +05:30
"github.com/gogits/gogs/modules/setting"
)
var c = cron.New()
2015-09-17 08:38:46 +05:30
func NewContext() {
2015-08-18 01:33:11 +05:30
var (
entry *cron.Entry
err error
)
2015-08-17 23:49:29 +05:30
if setting.Cron.UpdateMirror.Enabled {
2015-08-18 01:33:11 +05:30
entry, err = c.AddFunc("Update mirrors", setting.Cron.UpdateMirror.Schedule, models.MirrorUpdate)
if err != nil {
log.Fatal(4, "Cron[Update mirrors]: %v", err)
}
2015-08-17 23:49:29 +05:30
if setting.Cron.UpdateMirror.RunAtStart {
2015-08-18 01:33:11 +05:30
entry.Prev = time.Now()
2015-08-17 23:49:29 +05:30
go models.MirrorUpdate()
}
}
if setting.Cron.RepoHealthCheck.Enabled {
2015-08-18 01:33:11 +05:30
entry, err = c.AddFunc("Repository health check", setting.Cron.RepoHealthCheck.Schedule, models.GitFsck)
if err != nil {
log.Fatal(4, "Cron[Repository health check]: %v", err)
}
2015-08-17 23:49:29 +05:30
if setting.Cron.RepoHealthCheck.RunAtStart {
2015-08-18 01:33:11 +05:30
entry.Prev = time.Now()
2015-08-17 23:49:29 +05:30
go models.GitFsck()
}
}
if setting.Cron.CheckRepoStats.Enabled {
2015-08-18 01:33:11 +05:30
entry, err = c.AddFunc("Check repository statistics", setting.Cron.CheckRepoStats.Schedule, models.CheckRepoStats)
if err != nil {
log.Fatal(4, "Cron[Check repository statistics]: %v", err)
}
2015-08-17 23:49:29 +05:30
if setting.Cron.CheckRepoStats.RunAtStart {
2015-08-18 01:33:11 +05:30
entry.Prev = time.Now()
2015-08-17 23:49:29 +05:30
go models.CheckRepoStats()
}
}
c.Start()
}
// ListTasks returns all running cron tasks.
func ListTasks() []*cron.Entry {
return c.Entries()
}