1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-26 13:29:12 -05:00
forgejo/models/cron/cron.go

60 lines
1.5 KiB
Go
Raw Normal View History

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