This commit is contained in:
parent
efd44da3ab
commit
db3d6030d5
@ -6,6 +6,8 @@ import (
|
||||
|
||||
"git.fjla.uk/owlboard/go-types/pkg/upstreamApi"
|
||||
"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.
|
||||
@ -14,10 +16,12 @@ import (
|
||||
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
|
||||
if oldMeta == nil || newMeta == nil {
|
||||
log.Debug("oldMeta or newMeta is a nil pointer.")
|
||||
return "nil-pointer", false
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@ -28,6 +32,7 @@ func checkMetadata(oldMeta *dbAccess.CifMetadata, newMeta *upstreamApi.JsonTimet
|
||||
|
||||
// Check that the new metadata sequence is as expected.
|
||||
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
|
||||
} else {
|
||||
s := fmt.Sprintf("incorrect sequence, Old: %d, New: %d, Expected New: %d", oldMeta.LastSequence, newMeta.Metadata.Sequence, oldMeta.LastSequence+1)
|
||||
|
Loading…
Reference in New Issue
Block a user