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