Expand CIF updates to ensure new sequence number is equal to oldSequence +1
All checks were successful
Go Test / test (push) Successful in 32s

This commit is contained in:
Fred Boniface 2024-04-08 22:13:08 +01:00
parent f243fc6831
commit 19f180d711

View File

@ -1,6 +1,7 @@
package cif package cif
import ( import (
"errors"
"time" "time"
"git.fjla.uk/owlboard/timetable-mgr/dbAccess" "git.fjla.uk/owlboard/timetable-mgr/dbAccess"
@ -70,15 +71,32 @@ func runCifUpdateDownload(cfg *helpers.Configuration, metadata *dbAccess.CifMeta
return err return err
} }
// Check metadata sequence - Handle a metadata sequence error. Probably by deleting metadata so next update triggers full download // Check CIF Sequence
//// I need to check what the sequence looks like in a full download first. // Skip if LastSequence is >= to this sequence
//// Regarding metadata, I will need to replace 'metadata *dbAccess.CifMetadata' with the new metadata to ensure it is checked correctly in each iteration. if metadata.LastSequence >= parsed.header.Metadata.Sequence {
log.Msg.Info("Skipping CIF file, already processed", zap.Int64("LastSequence", metadata.LastSequence), zap.Int64("New sequence", parsed.header.Metadata.Sequence))
continue
}
// Fail if sequence number is not as expected
if parsed.header.Metadata.Sequence != metadata.LastSequence+1 {
err := errors.New("out of sequence CIF data")
log.Msg.Error("CIF sequence not as expected", zap.Error(err), zap.Int64("LastSequence", metadata.LastSequence), zap.Int64("New Sequence", parsed.header.Metadata.Sequence))
return err
}
// Do further sequence checks - parsed.header.Metadata.Sequence MUST = metadata.LastSequence + 1
log.Msg.Debug("CIF Data has passed checks and should now be processed <<<<<<")
// Process CIF file // Process CIF file
metadata = generateMetadata(&parsed.header) metadata = generateMetadata(&parsed.header)
} }
// Write metadata ok := dbAccess.PutCifMetadata(metadata)
if !ok {
log.Msg.Warn("CIF Data updated, but metadata write failed.")
}
return nil return nil
} }