feat: 为四种现有轮询 Handler 添加 verbose log 输出

realname: verbose log 移入 gateway 块内,避免 gateway=nil 时输出零值
carddata: 添加 && h.gateway != nil 门卫,确保仅 gateway 查询成功时输出
package: verbose log 在 freshCard 加载后、EvaluateAndAct 之前输出
protect: 引入 actionTaken 变量,字段名 network_status → network_status_at_check,新增 action_taken

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-04-15 12:22:25 +08:00
parent 6292443f69
commit 71559547b6
4 changed files with 41 additions and 0 deletions

View File

@@ -85,6 +85,8 @@ func (h *PollingProtectHandler) Handle(ctx context.Context, t *asynq.Task) error
stopProtect := h.base.redis.Exists(ctx, constants.RedisDeviceProtectKey(deviceID, "stop")).Val() > 0
startProtect := h.base.redis.Exists(ctx, constants.RedisDeviceProtectKey(deviceID, "start")).Val() > 0
actionTaken := "no_action"
switch {
case stopProtect && card.NetworkStatus == constants.NetworkStatusOnline:
// 保护期内:停机保护期发现开机卡 → 强制停机(绕过 EvaluateAndAct
@@ -107,6 +109,7 @@ func (h *PollingProtectHandler) Handle(ctx context.Context, t *asynq.Task) error
h.base.logger.Warn("保护期停机 DB 更新失败", zap.Uint("card_id", cardID), zap.Error(updateErr))
}
h.base.updateCardCache(ctx, cardID, map[string]any{"network_status": constants.NetworkStatusOffline})
actionTaken = "forced_stop"
case startProtect && card.NetworkStatus == constants.NetworkStatusOffline:
// 保护期内:复机保护期发现停机卡 → 强制复机(绕过 EvaluateAndAct
@@ -129,6 +132,7 @@ func (h *PollingProtectHandler) Handle(ctx context.Context, t *asynq.Task) error
h.base.logger.Warn("保护期复机 DB 更新失败", zap.Uint("card_id", cardID), zap.Error(updateErr))
}
h.base.updateCardCache(ctx, cardID, map[string]any{"network_status": constants.NetworkStatusOnline})
actionTaken = "forced_resume"
case !stopProtect && !startProtect:
// 保护期结束:调 EvaluateAndAct 重新评估正常停复机条件
@@ -138,6 +142,17 @@ func (h *PollingProtectHandler) Handle(ctx context.Context, t *asynq.Task) error
zap.Uint("card_id", cardID), zap.Error(evalErr))
}
}
actionTaken = "evaluate"
}
if h.base.verboseLog {
h.base.logger.Info("保护期检查详情",
zap.Uint("card_id", cardID),
zap.String("iccid", card.ICCID),
zap.Bool("stop_protect", stopProtect),
zap.Bool("start_protect", startProtect),
zap.Int("network_status_at_check", card.NetworkStatus),
zap.String("action_taken", actionTaken))
}
if updateErr := h.iotCardStore.UpdateFields(ctx, cardID, map[string]any{