2024-04-08 03:22:47 +02:00
|
|
|
package cron
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.gnous.eu/ada/git-mirror/internal/git"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
|
2024-04-08 03:29:41 +02:00
|
|
|
// start a regular background tasks.
|
2024-04-08 03:22:47 +02:00
|
|
|
func start(duration time.Duration, fn func(), name string) {
|
|
|
|
for {
|
|
|
|
time.Sleep(duration)
|
|
|
|
logrus.Info("Begin update job for: ", name)
|
|
|
|
fn()
|
|
|
|
logrus.Debug("Finished update job for: ", name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-08 03:29:41 +02:00
|
|
|
// Launch all repo update background tasks.
|
2024-04-08 03:22:47 +02:00
|
|
|
func Launch(duration time.Duration, config []git.RepoConfig) {
|
|
|
|
var counter int
|
|
|
|
for _, content := range config {
|
|
|
|
counter++
|
|
|
|
logrus.Debug("Launch background tasks for: ", content.Name)
|
|
|
|
go start(duration, content.Update, content.Name)
|
|
|
|
}
|
|
|
|
logrus.Info("Started: ", counter, " background tasks")
|
|
|
|
}
|