chore: update dependencies and improve bot configuration
- Upgrade Go version to 1.24.0 and update toolchain. - Update various dependencies in go.mod and go.sum, including: - Upgrade `fasthttp/websocket` to v1.5.12 - Upgrade `fsnotify/fsnotify` to v1.9.0 - Upgrade `valyala/fasthttp` to v1.58.0 - Add new dependencies for `bytedance/sonic` and `google/uuid`. - Refactor bot configuration in config.toml to support multiple bot protocols, including "milky" and "onebot11". - Modify internal configuration structures to accommodate new bot settings. - Enhance event dispatcher with metrics tracking and asynchronous processing capabilities. - Implement WebSocket connection management with heartbeat and reconnection logic. - Update server handling for bot management and event publishing.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"cellbot/internal/engine"
|
||||
"cellbot/internal/protocol"
|
||||
"cellbot/pkg/net"
|
||||
|
||||
"go.uber.org/fx"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
@@ -17,58 +18,59 @@ func RegisterLifecycleHooks(
|
||||
dispatcher *engine.Dispatcher,
|
||||
botManager *protocol.BotManager,
|
||||
server *net.Server,
|
||||
) fx.Option {
|
||||
return fx.Invoke(
|
||||
func(lc fx.Lifecycle) {
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
logger.Info("Starting CellBot application...")
|
||||
lc fx.Lifecycle,
|
||||
) {
|
||||
lc.Append(fx.Hook{
|
||||
OnStart: func(ctx context.Context) error {
|
||||
logger.Info("=== Starting CellBot application ===")
|
||||
|
||||
// 启动事件总线
|
||||
eventBus.Start()
|
||||
// 启动事件总线
|
||||
logger.Info("Starting event bus...")
|
||||
eventBus.Start()
|
||||
logger.Info("Event bus started")
|
||||
|
||||
// 启动分发器
|
||||
dispatcher.Start(ctx)
|
||||
// 启动分发器
|
||||
logger.Info("Starting dispatcher...")
|
||||
dispatcher.Start(ctx)
|
||||
logger.Info("Dispatcher started")
|
||||
|
||||
// 启动所有机器人
|
||||
if err := botManager.StartAll(ctx); err != nil {
|
||||
logger.Error("Failed to start bots", zap.Error(err))
|
||||
}
|
||||
// 启动所有机器人
|
||||
if err := botManager.StartAll(ctx); err != nil {
|
||||
logger.Error("Failed to start bots", zap.Error(err))
|
||||
}
|
||||
|
||||
// 启动HTTP服务器
|
||||
if err := server.Start(); err != nil {
|
||||
logger.Error("Failed to start server", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
// 启动HTTP服务器
|
||||
if err := server.Start(); err != nil {
|
||||
logger.Error("Failed to start server", zap.Error(err))
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Info("CellBot application started successfully")
|
||||
return nil
|
||||
},
|
||||
OnStop: func(ctx context.Context) error {
|
||||
logger.Info("Stopping CellBot application...")
|
||||
|
||||
// 停止HTTP服务器
|
||||
if err := server.Stop(); err != nil {
|
||||
logger.Error("Failed to stop server", zap.Error(err))
|
||||
}
|
||||
|
||||
// 停止所有机器人
|
||||
if err := botManager.StopAll(ctx); err != nil {
|
||||
logger.Error("Failed to stop bots", zap.Error(err))
|
||||
}
|
||||
|
||||
// 停止分发器
|
||||
dispatcher.Stop()
|
||||
|
||||
// 停止事件总线
|
||||
eventBus.Stop()
|
||||
|
||||
logger.Info("CellBot application stopped successfully")
|
||||
return nil
|
||||
},
|
||||
})
|
||||
logger.Info("CellBot application started successfully")
|
||||
return nil
|
||||
},
|
||||
)
|
||||
OnStop: func(ctx context.Context) error {
|
||||
logger.Info("Stopping CellBot application...")
|
||||
|
||||
// 停止HTTP服务器
|
||||
if err := server.Stop(); err != nil {
|
||||
logger.Error("Failed to stop server", zap.Error(err))
|
||||
}
|
||||
|
||||
// 停止所有机器人
|
||||
if err := botManager.StopAll(ctx); err != nil {
|
||||
logger.Error("Failed to stop bots", zap.Error(err))
|
||||
}
|
||||
|
||||
// 停止分发器
|
||||
dispatcher.Stop()
|
||||
|
||||
// 停止事件总线
|
||||
eventBus.Stop()
|
||||
|
||||
logger.Info("CellBot application stopped successfully")
|
||||
return nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// Lifecycle 生命周期管理选项
|
||||
|
||||
Reference in New Issue
Block a user