1
1
mirror of https://github.com/go-gitea/gitea synced 2024-11-01 07:44:25 +00:00
gitea/models/cron/cron.go

60 lines
1.5 KiB
Go
Raw Normal View History

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