timetable-mgr/corpus/check.go

39 lines
1.0 KiB
Go
Raw Normal View History

2024-03-26 16:04:42 +00:00
package corpus
import (
"time"
"git.fjla.uk/owlboard/timetable-mgr/dbAccess"
"git.fjla.uk/owlboard/timetable-mgr/helpers"
"git.fjla.uk/owlboard/timetable-mgr/log"
"go.uber.org/zap"
)
2024-04-03 22:25:27 +01:00
// Checks if the CORPUS Data needs updating, and calls an updater function if needed.
func CheckCorpus(cfg *helpers.Configuration) {
2024-04-14 19:03:13 +01:00
log.Debug("Checking age of CORPUS Data")
utime, err := dbAccess.CheckUpdateTime(dbAccess.CorpusCollection)
if err != nil {
2024-04-14 19:03:13 +01:00
log.Error("Error checking last CORPUS update", zap.Error(err))
}
lastUpdate := time.Unix(utime, 0)
currentTime := time.Now()
dataAge := currentTime.Sub(lastUpdate)
fortnight := 14 * 24 * time.Hour
2024-04-14 19:03:13 +01:00
log.Debug("CORPUS Data", zap.Duration("Data Age", dataAge), zap.Duration("Max Age", 14*24*time.Hour))
if dataAge >= fortnight {
2024-04-14 19:03:13 +01:00
log.Info("CORPUS Data is more than two weeks old")
err := RunCorpusUpdate(cfg)
if err != nil {
2024-04-14 19:03:13 +01:00
log.Warn("CORPUS Update did not run")
2024-04-03 22:25:27 +01:00
} else {
2024-04-14 19:03:13 +01:00
log.Info("CORPUS data has been updated")
}
} else {
2024-04-14 19:03:13 +01:00
log.Info("CORPUS Data is less than two weeks old, not updating")
}
}