init.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package event
  2. import (
  3. "context"
  4. "github.com/uozi-tech/cosy/logger"
  5. )
  6. // InitEventSystem initializes the event system and sets up WebSocket forwarding
  7. func InitEventSystem(ctx context.Context) {
  8. logger.Info("Initializing event system...")
  9. // Initialize the event bus by getting the singleton instance
  10. GetEventBus()
  11. // Initialize WebSocket event forwarding configurations
  12. initWebSocketEventForwarding()
  13. logger.Info("Event system initialized successfully")
  14. defer ShutdownEventSystem()
  15. <-ctx.Done()
  16. }
  17. // initWebSocketEventForwarding initializes WebSocket event forwarding configurations
  18. func initWebSocketEventForwarding() {
  19. // Register default event forwarding configurations
  20. RegisterWebSocketEventConfigs(GetDefaultWebSocketEventConfigs())
  21. logger.Info("WebSocket event forwarding initialized")
  22. }
  23. // ShutdownEventSystem gracefully shuts down the event system
  24. func ShutdownEventSystem() {
  25. logger.Info("Shutting down event system...")
  26. GetEventBus().Shutdown()
  27. logger.Info("Event system shutdown completed")
  28. }