From 76f206441a5cb360ef18056bfefb8b3203841e3d Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Sun, 14 Apr 2024 21:28:17 +0100 Subject: [PATCH] Tidy logging in package cif and dbAccess/cif.go --- cif/check.go | 4 ++-- cif/metadata.go | 12 ++++++++++++ cif/parse.go | 2 +- cif/process.go | 15 +-------------- dbAccess/cif.go | 3 --- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/cif/check.go b/cif/check.go index d832cb4..6c4123a 100644 --- a/cif/check.go +++ b/cif/check.go @@ -50,7 +50,7 @@ func CheckCif(cfg *helpers.Configuration) { log.Info("Full CIF download required") err := runCifFullDownload(cfg) if err != nil { - log.Error("Unable to run full CIF Update", zap.Error(err)) + log.Error("Full CIF update failed", zap.Error(err)) } return } @@ -61,6 +61,6 @@ func CheckCif(cfg *helpers.Configuration) { log.Info("CIF Update required", zap.Any("days to update", daysToUpdate)) err = runCifUpdateDownload(cfg, metadata, daysToUpdate) if err != nil { - log.Error("Unable to run CIF update", zap.Error(err)) + log.Error("Daily CIF update failed", zap.Error(err)) } } diff --git a/cif/metadata.go b/cif/metadata.go index 8f6e380..a1c9ae0 100644 --- a/cif/metadata.go +++ b/cif/metadata.go @@ -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) 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 +} diff --git a/cif/parse.go b/cif/parse.go index ed56d57..9bb1990 100644 --- a/cif/parse.go +++ b/cif/parse.go @@ -58,7 +58,7 @@ func parseCifDataStream(dataStream io.ReadCloser) (*parsedData, error) { } parsed.sched = append(parsed.sched, schedule) case "EOF": - log.Info("Reached EOF") + log.Debug("Reached EOF") default: log.Warn("Unknown CIF Data type", zap.String("key", key)) } diff --git a/cif/process.go b/cif/process.go index 6476452..ee10b05 100644 --- a/cif/process.go +++ b/cif/process.go @@ -1,8 +1,6 @@ package cif import ( - "time" - "git.fjla.uk/owlboard/go-types/pkg/database" "git.fjla.uk/owlboard/go-types/pkg/upstreamApi" "git.fjla.uk/owlboard/timetable-mgr/dbAccess" @@ -100,6 +98,7 @@ func doCreations(creations []*upstreamApi.JsonScheduleV1) error { document, err := ConvertServiceType(item, false) if err != nil { log.Error("Error converting JsonSchedule to Service type", zap.Error(err)) + continue } createDocuments = append(createDocuments, *document) @@ -113,15 +112,3 @@ func doCreations(creations []*upstreamApi.JsonScheduleV1) error { 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 -} diff --git a/dbAccess/cif.go b/dbAccess/cif.go index 6a1db98..f693cf8 100644 --- a/dbAccess/cif.go +++ b/dbAccess/cif.go @@ -36,7 +36,6 @@ func GetCifMetadata() (*CifMetadata, error) { if errors.Is(err, mongo.ErrNoDocuments) { return nil, nil } - log.Error("Error fetching CIF Metadata") return nil, err } @@ -103,7 +102,6 @@ func DeleteCifEntries(deletions []database.DeleteQuery) error { _, err := collection.BulkWrite(context.Background(), bulkDeletions, bulkWriteOptions) if err != nil { - log.Error("Error deleting documents", zap.Error(err)) return err } @@ -132,7 +130,6 @@ func CreateCifEntries(schedules []database.Service) error { _, err := collection.BulkWrite(context.Background(), models, bulkWriteOptions) if err != nil { - log.Error("Error inserting documents", zap.Error(err)) return err }