From 908fad0923778414abdb2618b4803084d40752df Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Fri, 19 Nov 2021 23:27:51 +0100 Subject: [PATCH] added configurable interval --- config_dist.yaml | 3 +++ main.go | 34 ++++++++++++++++++++++------------ utils.go | 3 +++ 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/config_dist.yaml b/config_dist.yaml index e50b40d..06f1ce2 100644 --- a/config_dist.yaml +++ b/config_dist.yaml @@ -21,6 +21,9 @@ basedir: march: - x86-64-v3 +housekeeping: + interval: 12h + blacklist: packages: - tensorflow diff --git a/main.go b/main.go index 3014850..258ad75 100644 --- a/main.go +++ b/main.go @@ -40,6 +40,7 @@ var ( db *ent.Client journalLog = flag.Bool("journal", false, "Log to systemd journal instead of stdout") checkInterval = flag.Int("interval", 5, "How often svn2git should be checked in minutes (default: 5)") + lastHKRun time.Time ) func (b *BuildManager) buildWorker(id int) { @@ -511,23 +512,32 @@ func (b *BuildManager) syncWorker() { } // housekeeping - wg := new(sync.WaitGroup) - for _, repo := range repos { - wg.Add(1) - repo := repo - go func() { - err := housekeeping(repo, wg) - if err != nil { - log.Warningf("[%s] Housekeeping failed: %v", repo, err) - } - }() + hkDur, err := time.ParseDuration(conf.Housekeeping.Interval) + if err != nil { + log.Warningf("Unable to parse housekeeping duration %s: %v", conf.Housekeeping.Interval, err) + hkDur, _ = time.ParseDuration("12h") + } + + if time.Since(lastHKRun) > hkDur { + lastHKRun = time.Now() + wg := new(sync.WaitGroup) + for _, repo := range repos { + wg.Add(1) + repo := repo + go func() { + err := housekeeping(repo, wg) + if err != nil { + log.Warningf("[%s] housekeeping failed: %v", repo, err) + } + }() + } + wg.Wait() } - wg.Wait() // fetch updates between sync runs b.alpmMutex.Lock() check(alpmHandle.Release()) - err := setupChroot() + err = setupChroot() for err != nil { log.Warningf("Unable to upgrade chroot, trying again later.") time.Sleep(time.Minute) diff --git a/utils.go b/utils.go index 13b2098..12f861b 100644 --- a/utils.go +++ b/utils.go @@ -84,6 +84,9 @@ type Conf struct { Repo []string LTO []string `yaml:"lto"` } + Housekeeping struct { + Interval string + } } type Globs []string