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" ) // Checks if the CORPUS Data needs updating, and calls an updater function if needed. func CheckCorpus(cfg *helpers.Configuration) { log.Debug("Checking age of CORPUS Data") utime, err := dbAccess.CheckUpdateTime(dbAccess.CorpusCollection) if err != nil { 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 log.Debug("CORPUS Data", zap.Duration("Data Age", dataAge), zap.Duration("Max Age", 14*24*time.Hour)) if dataAge >= fortnight { log.Info("CORPUS update required") err := RunCorpusUpdate(cfg) if err != nil { log.Warn("CORPUS Update did not run") } else { log.Info("CORPUS data has been updated") } } else { log.Info("CORPUS Data not stale, skipping updating") } }