2024-03-26 16:04:42 +00:00
|
|
|
package corpus
|
|
|
|
|
2024-03-26 22:33:11 +00:00
|
|
|
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.
|
2024-03-26 22:33:11 +00:00
|
|
|
func CheckCorpus(cfg *helpers.Configuration) {
|
2024-04-14 19:03:13 +01:00
|
|
|
log.Debug("Checking age of CORPUS Data")
|
2024-03-26 22:33:11 +00:00
|
|
|
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))
|
2024-03-26 22:33:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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))
|
2024-03-26 22:33:11 +00:00
|
|
|
|
|
|
|
if dataAge >= fortnight {
|
2024-04-14 21:20:17 +01:00
|
|
|
log.Info("CORPUS update required")
|
2024-03-26 22:33:11 +00:00
|
|
|
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")
|
2024-03-26 22:33:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
2024-04-14 21:20:17 +01:00
|
|
|
log.Info("CORPUS Data not stale, skipping updating")
|
2024-03-26 22:33:11 +00:00
|
|
|
}
|
|
|
|
}
|