feat: 退款资产后处理逐次尝试记录与重试上限,停复机指令调用前结束写跳过记录
- 新增 tb_refund_post_process_attempt,每次尝试一条(步骤、触发方式、结果、错误码与信息、耗时) - 退款单增加 asset_post_status/attempts/last_error/next_at;失败按 2^(n-1) 分钟退避(最长 1 小时),10 次后转人工 - 中间失败只写应用日志,成功或转人工写一条结论审计(带总尝试次数、首次失败时间、最后错误码) - 补偿扫描跳过需人工处理与未到重试时间的退款单,Outbox 不再无限重投 - 新增 POST /refunds/:id/asset-post-processing/retry 人工重试 - 停复机指令执行前结束(已是目标状态、条件不再满足、需相反动作)写 skipped 停复机记录 - 迁移 000271 需维护者在测试库执行后再部署 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
stderrors "errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
@@ -25,6 +26,7 @@ type StopResumeCommandService interface {
|
||||
ConfirmCommandState(ctx context.Context, card *model.IotCard, action, reason string) error
|
||||
EvaluateDeviceCommands(ctx context.Context, deviceID uint, scenes []string) error
|
||||
LegacyDeviceOpLocked(ctx context.Context, deviceID uint) bool
|
||||
RecordCommandSkipped(ctx context.Context, card *model.IotCard, action, scene, reason, skipReason string)
|
||||
}
|
||||
|
||||
// stopResumeTaskTimeout 是一条停复机指令的总执行时长上限(一次判断 + 一次网关调用)。
|
||||
@@ -148,6 +150,7 @@ func (e *StopResumeExecutor) execute(ctx context.Context, msg carrierqueue.StopR
|
||||
e.logger.Info("停复机指令执行前重新判断不再需要,结束指令", zap.Uint("card_id", msg.CardID),
|
||||
zap.String("action", cmd.Action), zap.String("decided", decision.Action), zap.Strings("scenes", cmd.Scenes))
|
||||
e.recovered(cmd, card)
|
||||
e.service.RecordCommandSkipped(ctx, card, cmd.Action, skipScene(cmd.Scenes), cmd.Reason, skipReason(card, cmd.Action, decision.Action))
|
||||
return srEnded()
|
||||
}
|
||||
if clearedPending {
|
||||
@@ -330,6 +333,33 @@ func (e *StopResumeExecutor) recovered(cmd carrierqueue.CommandState, card *mode
|
||||
}
|
||||
}
|
||||
|
||||
// 停复机指令执行前结束的原因(写入"跳过"停复机记录)。
|
||||
const (
|
||||
srSkipAlreadyTarget = "执行前已是目标状态"
|
||||
srSkipConditionNotMet = "执行前判断停复机条件不再满足"
|
||||
srSkipOppositeAction = "执行前判断需要相反动作"
|
||||
)
|
||||
|
||||
// skipReason 返回指令执行前结束的原因。
|
||||
func skipReason(card *model.IotCard, action, decided string) string {
|
||||
if card != nil && card.NetworkStatus == targetNetworkStatus(action) {
|
||||
return srSkipAlreadyTarget
|
||||
}
|
||||
if decided != "" {
|
||||
return srSkipOppositeAction
|
||||
}
|
||||
return srSkipConditionNotMet
|
||||
}
|
||||
|
||||
// skipScene 把指令的场景合并为记录的场景字段(列宽 50)。
|
||||
func skipScene(scenes []string) string {
|
||||
scene := strings.Join(scenes, ",")
|
||||
if len(scene) > 50 {
|
||||
return scene[:50]
|
||||
}
|
||||
return scene
|
||||
}
|
||||
|
||||
func targetNetworkStatus(action string) int {
|
||||
if action == constants.StopResumeActionStop {
|
||||
return constants.NetworkStatusOffline
|
||||
|
||||
Reference in New Issue
Block a user