spiegel/internal/cron/start.go
Ada 5b67a66d74
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/lint Pipeline was successful
Support clone of archived repo via /git/<name>
2024-05-26 22:00:55 +02:00

29 lines
683 B
Go

package cron
import (
"time"
"git.gnous.eu/ada/spiegel/internal/git"
"github.com/sirupsen/logrus"
)
// start a regular background tasks.
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)
}
}
// Launch all repo update background tasks.
func Launch(duration time.Duration, config []git.Config) {
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")
}