fix: 修复禁用所有轮询配置重启后再启用无法工作的问题
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m23s

- 新增 RedisPollingConfigChangedChannel 常量,用于跨进程配置变更通知
- ConfigService 注入 Redis,Create/Delete/UpdateStatus 后发布 Pub/Sub 事件
- PollingConfigManager 新增 WatchChanges() 方法,收到通知立即刷新内存缓存
- PollingInitializer 新增 Restart() 方法,支持初始化完成后安全重启(CAS 防并发)
- Worker 订阅配置变更事件,configs 从空变为非空时触发 Initializer.Restart()

根因:启动时所有配置禁用导致分片队列为空,Initializer 是一次性的,
之后启用配置只更新 DB 但不重建队列,调度器无卡可处理
This commit is contained in:
2026-04-16 17:32:43 +08:00
parent 0ec16d4afa
commit aef20d2ab1
6 changed files with 86 additions and 3 deletions

View File

@@ -157,6 +157,14 @@ func main() {
pollingInitializer := polling.NewPollingInitializer(pollingIotCardStore, redisClient, pollingConfigMgr, pollingQueueMgr, appLogger)
pollingInitializer.StartBackground(ctx)
// 订阅配置变更事件:配置从空变为非空时重启 Initializer将卡重新入队
pollingConfigMgr.WatchChanges(ctx, func(hadConfigs, hasConfigs bool) {
if !hadConfigs && hasConfigs {
appLogger.Info("轮询配置从空变为非空,触发队列重新初始化")
pollingInitializer.Restart(ctx)
}
})
// 创建生命周期服务Worker 进程用,功能更完整)
pollingDeviceSimBindingStore := postgres.NewDeviceSimBindingStore(db, redisClient)
pollingDeviceStore := postgres.NewDeviceStore(db, redisClient)