增加心跳
This commit is contained in:
@@ -45,6 +45,9 @@ type Application struct {
|
||||
// DeviceStatusPool 设备状态池实例
|
||||
DeviceStatusPool *service.DeviceStatusPool
|
||||
|
||||
// HeartbeatService 心跳服务实例
|
||||
HeartbeatService *service.HeartbeatService
|
||||
|
||||
// Config 应用配置
|
||||
Config *config.Config
|
||||
|
||||
@@ -103,8 +106,11 @@ func (app *Application) Start() error {
|
||||
// 设置WebSocket超时时间
|
||||
app.WebSocketService.SetDefaultTimeout(app.Config.GetWebSocketTimeout())
|
||||
|
||||
// 初始化心跳服务
|
||||
app.HeartbeatService = service.NewHeartbeatService(app.WebSocketService, app.DeviceStatusPool, app.DeviceRepo, app.Config)
|
||||
|
||||
// 初始化API组件
|
||||
app.API = api.NewAPI(app.Config, app.UserRepo, app.OperationHistoryRepo, app.DeviceControlRepo, app.DeviceRepo, app.WebSocketService, app.DeviceStatusPool)
|
||||
app.API = api.NewAPI(app.Config, app.UserRepo, app.OperationHistoryRepo, app.DeviceControlRepo, app.DeviceRepo, app.WebSocketService, app.HeartbeatService, app.DeviceStatusPool)
|
||||
|
||||
// 初始化任务执行器组件(使用5个工作协程)
|
||||
app.TaskExecutor = task.NewExecutor(5)
|
||||
@@ -119,6 +125,9 @@ func (app *Application) Start() error {
|
||||
app.logger.Info("启动任务执行器")
|
||||
app.TaskExecutor.Start()
|
||||
|
||||
// 启动心跳服务
|
||||
app.logger.Info("启动心跳服务")
|
||||
app.HeartbeatService.Start()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -134,6 +143,10 @@ func (app *Application) Stop() error {
|
||||
app.logger.Info("停止任务执行器")
|
||||
app.TaskExecutor.Stop()
|
||||
|
||||
// 停止心跳服务
|
||||
app.logger.Info("停止心跳服务")
|
||||
app.HeartbeatService.Stop()
|
||||
|
||||
// 停止存储组件
|
||||
if err := app.Storage.Disconnect(); err != nil {
|
||||
return fmt.Errorf("存储断开连接失败: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user