0
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-12-11 17:05:58 +01:00
gitea/models/cron/cron.go

60 lines
1.5 KiB
Go
Raw Normal View History

2015-08-17 20:19:29 +02:00
// 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-17 22:03:11 +02:00
"time"
2015-08-17 20:19:29 +02:00
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/cron"
2015-08-17 22:03:11 +02:00
"github.com/gogits/gogs/modules/log"
2015-08-17 20:19:29 +02:00
"github.com/gogits/gogs/modules/setting"
)
var c = cron.New()
func NewCronContext() {
2015-08-17 22:03:11 +02:00
var (
entry *cron.Entry
err error
)
2015-08-17 20:19:29 +02:00
if setting.Cron.UpdateMirror.Enabled {
2015-08-17 22:03:11 +02:00
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 20:19:29 +02:00
if setting.Cron.UpdateMirror.RunAtStart {
2015-08-17 22:03:11 +02:00
entry.Prev = time.Now()
2015-08-17 20:19:29 +02:00
go models.MirrorUpdate()
}
}
if setting.Cron.RepoHealthCheck.Enabled {
2015-08-17 22:03:11 +02:00
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 20:19:29 +02:00
if setting.Cron.RepoHealthCheck.RunAtStart {
2015-08-17 22:03:11 +02:00
entry.Prev = time.Now()
2015-08-17 20:19:29 +02:00
go models.GitFsck()
}
}
if setting.Cron.CheckRepoStats.Enabled {
2015-08-17 22:03:11 +02:00
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 20:19:29 +02:00
if setting.Cron.CheckRepoStats.RunAtStart {
2015-08-17 22:03:11 +02:00
entry.Prev = time.Now()
2015-08-17 20:19:29 +02:00
go models.CheckRepoStats()
}
}
c.Start()
}
// ListTasks returns all running cron tasks.
func ListTasks() []*cron.Entry {
return c.Entries()
}