timetable-mgr/src/vstp/handler.go

42 lines
914 B
Go
Raw Normal View History

2023-07-19 21:31:00 +01:00
package vstp
import (
"encoding/json"
"fmt"
"io/ioutil"
"time"
//"git.fjla.uk/owlboard/go-types/pkg/database"
2023-07-19 21:31:00 +01:00
"git.fjla.uk/owlboard/mq-client/log"
"github.com/go-stomp/stomp/v3"
)
var count uint64 = 0
func handle(msg *stomp.Message) {
count++
log.Msg.Info("Message count: " + fmt.Sprint(count))
schedule := unmarshalData(string(msg.Body))
processEntryType(schedule)
saveToFile(schedule, "transformed")
2023-07-19 21:31:00 +01:00
}
func saveToFile(msg any, suffix string) {
2023-07-19 21:31:00 +01:00
timestamp := time.Now().Format("2006-01-02T15:04:05")
path := fmt.Sprintf("message-logs/%s-%s.json", timestamp, suffix)
2023-07-19 21:31:00 +01:00
prettyJSON, err := json.MarshalIndent(msg, "", " ")
if err != nil {
log.Msg.Error("Error marshaling data to JSON: " + err.Error())
return
}
err = ioutil.WriteFile(path, prettyJSON, 0644)
if err != nil {
log.Msg.Error("Error saving message: " + err.Error())
return
}
log.Msg.Info("Saved message to: " + path)
}