Organize cleanup code
This commit is contained in:
parent
849f23b507
commit
9fa0f7d61f
@ -54,3 +54,15 @@ func initDataAccess() *mongo.Client {
|
||||
}
|
||||
return client
|
||||
}
|
||||
|
||||
func CloseMongoClient() {
|
||||
if MongoClient != nil {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
if err := MongoClient.Disconnect(ctx); err != nil {
|
||||
log.Msg.Warn("Error disconnecting MongoDB client: " + err.Error())
|
||||
} else {
|
||||
log.Msg.Info("MongoDB client disconnected.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,14 @@ import (
|
||||
|
||||
func main() {
|
||||
log.Msg.Info("Initialised OwlBoard MQ Client " + helpers.Version)
|
||||
defer cleanup()
|
||||
dbAccess.PrintFromDbPackage()
|
||||
defer messaging.Disconnect(messaging.Client)
|
||||
vstp.Subscribe()
|
||||
}
|
||||
|
||||
func cleanup() {
|
||||
log.Msg.Debug("Cleaning up open connections")
|
||||
defer messaging.Disconnect(messaging.Client)
|
||||
defer dbAccess.CloseMongoClient()
|
||||
log.Msg.Info("Program ready to exit")
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ func Subscribe() {
|
||||
for {
|
||||
msg := <-sub.C
|
||||
if msg.Err != nil {
|
||||
log.Msg.Error("\nSTOMP Message Error: " + msg.Err.Error())
|
||||
log.Msg.Error("STOMP Message Error: " + msg.Err.Error())
|
||||
} else {
|
||||
log.Msg.Debug("\nSTOMP Message Received")
|
||||
log.Msg.Debug("STOMP Message Received")
|
||||
saveToFile(string(msg.Body), "msgBody")
|
||||
handle(msg)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user