新增上游的停机原因
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m5s

This commit is contained in:
2026-05-12 11:13:04 +08:00
parent 95fc0b0a1b
commit 8f3a68a673
22 changed files with 83 additions and 3 deletions

View File

@@ -65,6 +65,8 @@ func (h *PollingCardStatusHandler) Handle(ctx context.Context, t *asynq.Task) er
newNetworkStatus := card.NetworkStatus
gatewayCardStatus := ""
gatewayExtend := card.GatewayExtend
statusQueried := false
if h.gateway != nil {
result, gwErr := h.gateway.QueryCardStatus(ctx, &gateway.CardStatusReq{CardNo: card.ICCID})
if gwErr != nil {
@@ -74,6 +76,8 @@ func (h *PollingCardStatusHandler) Handle(ctx context.Context, t *asynq.Task) er
return h.base.requeueCard(ctx, cardID, constants.TaskTypePollingCardStatus)
}
gatewayCardStatus = result.CardStatus
gatewayExtend = result.Extend
statusQueried = true
parsedStatus, ok := gateway.ParseCardNetworkStatus(result.CardStatus, result.Extend)
if !ok {
h.base.logger.Warn("卡状态轮询:未知 Gateway 卡状态",
@@ -100,6 +104,9 @@ func (h *PollingCardStatusHandler) Handle(ctx context.Context, t *asynq.Task) er
// 无论状态是否变化,都更新最后一次检查时间
fields := map[string]any{"last_card_status_check_at": now}
if statusQueried {
fields["gateway_extend"] = gatewayExtend
}
if statusChanged {
fields["network_status"] = newNetworkStatus
// 网关侧停机事件:补写 stop_reason便于状态追踪和区分手动停机
@@ -116,8 +123,18 @@ func (h *PollingCardStatusHandler) Handle(ctx context.Context, t *asynq.Task) er
return h.base.requeueCard(ctx, cardID, constants.TaskTypePollingCardStatus)
}
if statusQueried || statusChanged {
cacheUpdates := map[string]any{}
if statusQueried {
cacheUpdates["gateway_extend"] = gatewayExtend
}
if statusChanged {
cacheUpdates["network_status"] = newNetworkStatus
}
h.base.updateCardCache(ctx, cardID, cacheUpdates)
}
if statusChanged {
h.base.updateCardCache(ctx, cardID, map[string]any{"network_status": newNetworkStatus})
h.base.logger.Info("卡状态已变化",
zap.Uint("card_id", cardID),
zap.Int("old_status", card.NetworkStatus),