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
import (
"errors"
"time"
"git.fjla.uk/owlboard/timetable-mgr/dbAccess"
@ -70,15 +71,32 @@ func runCifUpdateDownload(cfg *helpers.Configuration, metadata *dbAccess.CifMeta
return err
}
// Check metadata sequence - Handle a metadata sequence error. Probably by deleting metadata so next update triggers full download
//// I need to check what the sequence looks like in a full download first.
//// Regarding metadata, I will need to replace 'metadata *dbAccess.CifMetadata' with the new metadata to ensure it is checked correctly in each iteration.
// Check CIF Sequence
// Skip if LastSequence is >= to this sequence
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
metadata = generateMetadata(&parsed.header)
}
// Write metadata
ok := dbAccess.PutCifMetadata(metadata)
if !ok {
log.Msg.Warn("CIF Data updated, but metadata write failed.")
}
return nil
}