diff --git a/main.go b/main.go index bbb501c..726b4a9 100644 --- a/main.go +++ b/main.go @@ -74,10 +74,9 @@ func handleSignals(cfg *helpers.Configuration, stop chan<- struct{}) { func cleanup(cfg *helpers.Configuration, stop chan<- struct{}) { log.Debug("Cleaning up open connections") if cfg.VstpOn { - if messaging.Client != nil { - log.Info("Closing STOMP Client") - messaging.Disconnect(messaging.Client) - } + log.Info("Closing STOMP Client") + messaging.Disconnect(messaging.Client) + } if dbAccess.MongoClient != nil { log.Info("Closing MongoDB Client") diff --git a/messaging/client.go b/messaging/client.go index ae95680..6d3b293 100644 --- a/messaging/client.go +++ b/messaging/client.go @@ -22,7 +22,7 @@ func dial(user, pass string) *stomp.Conn { ) if err != nil { log.Fatal("Unable to connect to STOMP Client: " + err.Error()) - conn.MustDisconnect() + conn.Disconnect() } log.Info("Initialised STOMP Client") @@ -42,6 +42,11 @@ func Disconnect(conn *stomp.Conn) { return } log.Error("STOMP Disconnect failed, next connection attempt may fail") -} + err := Client.Disconnect() + if err != nil { + Client.MustDisconnect() + log.Warn("STOMP Disconnect failed, forced disconnection") + } + log.Info("STOMP Client disconnected") -// Register against the MQ Server and log each message for testing purposes +} diff --git a/vstp/actions.go b/vstp/actions.go index 4fc148d..8d8d06b 100644 --- a/vstp/actions.go +++ b/vstp/actions.go @@ -39,7 +39,6 @@ func processCifData(s *upstreamApi.JsonScheduleV1) error { } return nil } else { - err := fmt.Errorf("unknown transaction type: %s", s.TransactionType) - return err + return fmt.Errorf("unknown transaction type: %s", s.TransactionType) } } diff --git a/vstp/handler.go b/vstp/handler.go index 9d175fd..b87d0db 100644 --- a/vstp/handler.go +++ b/vstp/handler.go @@ -1,6 +1,8 @@ package vstp import ( + "time" + "git.fjla.uk/owlboard/timetable-mgr/log" "github.com/go-stomp/stomp/v3" "go.uber.org/zap" @@ -9,6 +11,7 @@ import ( var count uint64 = 0 func handle(msg *stomp.Message) { + start := time.Now() count++ log.Info("Message received", zap.Uint64("total since startup", count)) schedule, err := unmarshalData(string(msg.Body)) @@ -19,4 +22,7 @@ func handle(msg *stomp.Message) { if err != nil { log.Error("Error processing VSTP Schedule", zap.Error(err)) } + end := time.Now() + duration := start.Sub(end) + log.Info("Message processed", zap.Duration("processing-time", duration)) }