Tidy logging in package cif and dbAccess/cif.go
This commit is contained in:
parent
c9f894bbe6
commit
76f206441a
@ -50,7 +50,7 @@ func CheckCif(cfg *helpers.Configuration) {
|
|||||||
log.Info("Full CIF download required")
|
log.Info("Full CIF download required")
|
||||||
err := runCifFullDownload(cfg)
|
err := runCifFullDownload(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to run full CIF Update", zap.Error(err))
|
log.Error("Full CIF update failed", zap.Error(err))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -61,6 +61,6 @@ func CheckCif(cfg *helpers.Configuration) {
|
|||||||
log.Info("CIF Update required", zap.Any("days to update", daysToUpdate))
|
log.Info("CIF Update required", zap.Any("days to update", daysToUpdate))
|
||||||
err = runCifUpdateDownload(cfg, metadata, daysToUpdate)
|
err = runCifUpdateDownload(cfg, metadata, daysToUpdate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to run CIF update", zap.Error(err))
|
log.Error("Daily CIF update failed", zap.Error(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,3 +37,15 @@ func isAfterYesterdayAt0600(t time.Time) bool {
|
|||||||
yesterday0600 = time.Date(yesterday0600.Year(), yesterday0600.Month(), yesterday0600.Day(), 6, 0, 0, 0, time.UTC)
|
yesterday0600 = time.Date(yesterday0600.Year(), yesterday0600.Month(), yesterday0600.Day(), 6, 0, 0, 0, time.UTC)
|
||||||
return t.After(yesterday0600)
|
return t.After(yesterday0600)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Accepts the JsonTimetableV1 struct which contains CIF File metadata and produces a DB Ready struct.
|
||||||
|
func generateMetadata(header *upstreamApi.JsonTimetableV1) *dbAccess.CifMetadata {
|
||||||
|
newMetadata := dbAccess.CifMetadata{
|
||||||
|
Doctype: dbAccess.Doctype,
|
||||||
|
LastTimestamp: header.Timestamp,
|
||||||
|
LastUpdate: time.Now().In(londonTimezone),
|
||||||
|
LastSequence: header.Metadata.Sequence,
|
||||||
|
}
|
||||||
|
|
||||||
|
return &newMetadata
|
||||||
|
}
|
||||||
|
@ -58,7 +58,7 @@ func parseCifDataStream(dataStream io.ReadCloser) (*parsedData, error) {
|
|||||||
}
|
}
|
||||||
parsed.sched = append(parsed.sched, schedule)
|
parsed.sched = append(parsed.sched, schedule)
|
||||||
case "EOF":
|
case "EOF":
|
||||||
log.Info("Reached EOF")
|
log.Debug("Reached EOF")
|
||||||
default:
|
default:
|
||||||
log.Warn("Unknown CIF Data type", zap.String("key", key))
|
log.Warn("Unknown CIF Data type", zap.String("key", key))
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package cif
|
package cif
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
"git.fjla.uk/owlboard/go-types/pkg/database"
|
"git.fjla.uk/owlboard/go-types/pkg/database"
|
||||||
"git.fjla.uk/owlboard/go-types/pkg/upstreamApi"
|
"git.fjla.uk/owlboard/go-types/pkg/upstreamApi"
|
||||||
"git.fjla.uk/owlboard/timetable-mgr/dbAccess"
|
"git.fjla.uk/owlboard/timetable-mgr/dbAccess"
|
||||||
@ -100,6 +98,7 @@ func doCreations(creations []*upstreamApi.JsonScheduleV1) error {
|
|||||||
document, err := ConvertServiceType(item, false)
|
document, err := ConvertServiceType(item, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error converting JsonSchedule to Service type", zap.Error(err))
|
log.Error("Error converting JsonSchedule to Service type", zap.Error(err))
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
createDocuments = append(createDocuments, *document)
|
createDocuments = append(createDocuments, *document)
|
||||||
@ -113,15 +112,3 @@ func doCreations(creations []*upstreamApi.JsonScheduleV1) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accepts the JsonTimetableV1 struct which contains CIF File metadata and produces a DB Ready struct.
|
|
||||||
func generateMetadata(header *upstreamApi.JsonTimetableV1) *dbAccess.CifMetadata {
|
|
||||||
newMetadata := dbAccess.CifMetadata{
|
|
||||||
Doctype: dbAccess.Doctype,
|
|
||||||
LastTimestamp: header.Timestamp,
|
|
||||||
LastUpdate: time.Now().In(londonTimezone),
|
|
||||||
LastSequence: header.Metadata.Sequence,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &newMetadata
|
|
||||||
}
|
|
||||||
|
@ -36,7 +36,6 @@ func GetCifMetadata() (*CifMetadata, error) {
|
|||||||
if errors.Is(err, mongo.ErrNoDocuments) {
|
if errors.Is(err, mongo.ErrNoDocuments) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
log.Error("Error fetching CIF Metadata")
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +102,6 @@ func DeleteCifEntries(deletions []database.DeleteQuery) error {
|
|||||||
|
|
||||||
_, err := collection.BulkWrite(context.Background(), bulkDeletions, bulkWriteOptions)
|
_, err := collection.BulkWrite(context.Background(), bulkDeletions, bulkWriteOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error deleting documents", zap.Error(err))
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +130,6 @@ func CreateCifEntries(schedules []database.Service) error {
|
|||||||
|
|
||||||
_, err := collection.BulkWrite(context.Background(), models, bulkWriteOptions)
|
_, err := collection.BulkWrite(context.Background(), models, bulkWriteOptions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error inserting documents", zap.Error(err))
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user