1. 增加状态池初始化
2. 把状态池注入需要的地方
This commit is contained in:
@@ -42,6 +42,9 @@ type Application struct {
|
||||
// WebSocketService WebSocket服务实例
|
||||
WebSocketService *service.WebSocketService
|
||||
|
||||
// DeviceStatusPool 设备状态池实例
|
||||
DeviceStatusPool *service.DeviceStatusPool
|
||||
|
||||
// Config 应用配置
|
||||
Config *config.Config
|
||||
|
||||
@@ -90,13 +93,18 @@ func (app *Application) Start() error {
|
||||
// 初始化设备仓库
|
||||
app.DeviceRepo = repository.NewDeviceRepo(app.Storage.GetDB())
|
||||
|
||||
// 初始化设备状态池
|
||||
app.DeviceStatusPool = service.NewDeviceStatusPool()
|
||||
|
||||
// 初始化WebSocket服务
|
||||
app.WebSocketService = service.NewWebSocketService(app.DeviceRepo)
|
||||
// 设置设备状态池
|
||||
app.WebSocketService.SetDeviceStatusPool(app.DeviceStatusPool)
|
||||
// 设置WebSocket超时时间
|
||||
app.WebSocketService.SetDefaultTimeout(app.Config.GetWebSocketTimeout())
|
||||
|
||||
// 初始化API组件
|
||||
app.API = api.NewAPI(app.Config, app.UserRepo, app.OperationHistoryRepo, app.DeviceControlRepo, app.DeviceRepo, app.WebSocketService)
|
||||
app.API = api.NewAPI(app.Config, app.UserRepo, app.OperationHistoryRepo, app.DeviceControlRepo, app.DeviceRepo, app.WebSocketService, app.DeviceStatusPool)
|
||||
|
||||
// 初始化任务执行器组件(使用5个工作协程)
|
||||
app.TaskExecutor = task.NewExecutor(5)
|
||||
|
||||
Reference in New Issue
Block a user