timetable-extension #1
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user