fix: 修复轮询系统缓存不一致和可观测性问题
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled

- OnCardStatusChanged/Enabled/Disabled 添加 InvalidateCardCache,
  解决 Refresh API 更新 DB 后 polling 缓存仍为旧值的 bug
- AssetResolveResponse 的 enable_polling/network_status 去掉
  omitempty,解决 false/0 时字段从响应中消失的问题
- Scheduler/Initializer/PackageHandler 增加 INFO 级别日志,
  可通过日志判断轮询是否工作、处理了哪些卡
This commit is contained in:
2026-04-10 15:52:38 +08:00
parent ef8ec025bd
commit 2a7ac3f86e
6 changed files with 58 additions and 28 deletions

View File

@@ -199,6 +199,8 @@ func (p *PollingInitializer) initBatch(ctx context.Context, cards []*model.IotCa
cardCacheTTL := 7 * 24 * time.Hour
pipe := p.redis.Pipeline()
cmdCount := 0
enqueuedCards := 0
skippedCards := 0
flushPipe := func() {
if cmdCount == 0 {
@@ -214,8 +216,10 @@ func (p *PollingInitializer) initBatch(ctx context.Context, cards []*model.IotCa
for _, card := range cards {
cfg := p.configMgr.MatchConfig(card)
if cfg == nil {
skippedCards++
continue
}
enqueuedCards++
shardID := int(card.ID) % p.queueMgr.shardCount
cardIDStr := fmt.Sprintf("%d", card.ID)
@@ -273,6 +277,10 @@ func (p *PollingInitializer) initBatch(ctx context.Context, cards []*model.IotCa
}
flushPipe()
p.logger.Info("批量初始化完成",
zap.Int("total", len(cards)),
zap.Int("enqueued", enqueuedCards),
zap.Int("skipped_no_config", skippedCards))
return nil
}