timetable-extension #1

Open
fred.boniface wants to merge 154 commits from timetable-extension into main
Showing only changes of commit db3d6030d5 - Show all commits

View File

@ -6,6 +6,8 @@ import (
"git.fjla.uk/owlboard/go-types/pkg/upstreamApi" "git.fjla.uk/owlboard/go-types/pkg/upstreamApi"
"git.fjla.uk/owlboard/timetable-mgr/dbAccess" "git.fjla.uk/owlboard/timetable-mgr/dbAccess"
"git.fjla.uk/owlboard/timetable-mgr/log"
"go.uber.org/zap"
) )
// Evaluates last and new metadata and determines whether an update is required. // Evaluates last and new metadata and determines whether an update is required.
@ -14,10 +16,12 @@ import (
func checkMetadata(oldMeta *dbAccess.CifMetadata, newMeta *upstreamApi.JsonTimetableV1) (reason string, updateRequired bool) { func checkMetadata(oldMeta *dbAccess.CifMetadata, newMeta *upstreamApi.JsonTimetableV1) (reason string, updateRequired bool) {
// Handle nil pointer - although this should be resolved in the calling function in ideal situations // Handle nil pointer - although this should be resolved in the calling function in ideal situations
if oldMeta == nil || newMeta == nil { if oldMeta == nil || newMeta == nil {
log.Debug("oldMeta or newMeta is a nil pointer.")
return "nil-pointer", false return "nil-pointer", false
} }
if !isTimestampWithinLastFiveDays(newMeta.Timestamp) { if !isTimestampWithinLastFiveDays(newMeta.Timestamp) {
log.Debug("Downloaded CIF File not produced in last five days", zap.Time("file_timestamp", time.Unix(newMeta.Timestamp, 0)))
return "downloaded-data-is-too-old", false return "downloaded-data-is-too-old", false
} }
@ -28,6 +32,7 @@ func checkMetadata(oldMeta *dbAccess.CifMetadata, newMeta *upstreamApi.JsonTimet
// Check that the new metadata sequence is as expected. // Check that the new metadata sequence is as expected.
if newMeta.Metadata.Sequence == oldMeta.LastSequence+1 { if newMeta.Metadata.Sequence == oldMeta.LastSequence+1 {
log.Debug("Sequence numbers", zap.Int64("New", newMeta.Metadata.Sequence), zap.Int64("Old", oldMeta.LastSequence))
return "correct-sequence", true return "correct-sequence", true
} else { } else {
s := fmt.Sprintf("incorrect sequence, Old: %d, New: %d, Expected New: %d", oldMeta.LastSequence, newMeta.Metadata.Sequence, oldMeta.LastSequence+1) s := fmt.Sprintf("incorrect sequence, Old: %d, New: %d, Expected New: %d", oldMeta.LastSequence, newMeta.Metadata.Sequence, oldMeta.LastSequence+1)