feat: 停复机指令队列与设备维度判断
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled

自动停复机统一经停复机指令队列执行(全局开关 polling.stop_resume.queue_enabled,默认关闭):
- 统一判断函数 decideCard,新旧路径共用;暂停轮询的卡在套餐到期、退款场景照常停机
- 同卡一条指令、版本号覆盖;领取校验单卡最小重试间隔;先于卡任务领取,不受 scheduler_mode 限制
- 执行器只调用一次网关,按错误分类退避与告警,结果未知在队列内确认
- 设备维度判断合并请求与场景,版本变化再判断,旧路径持设备锁时推后
- 套餐激活、重置、订单、流量扣减、套餐到期、退款、实名管控修改改为请求评估
- 监控增加停复机队列与近 1 小时执行计数,单卡轮询状态返回当前指令
- 迁移 000255 插入开关与告警、退避参数

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
邹进
2026-10-26 00:36:26 +09:00
parent 1369fed642
commit 934a3a27a1
31 changed files with 2275 additions and 117 deletions

View File

@@ -0,0 +1,41 @@
// Package stopresume 提供自动停复机请求评估场景在 ctx 中的传递,供各自动入口与停复机服务共用(无业务依赖)。
package stopresume
import (
"context"
"github.com/break/junhong_cmp_fiber/pkg/constants"
)
type sceneKey struct{}
// WithScene 声明本次自动停复机评估的触发场景(constants.StopResumeScene*);未声明时按套餐步骤(周期评估)处理。
func WithScene(ctx context.Context, scene string) context.Context {
if scene == "" {
return ctx
}
return context.WithValue(ctx, sceneKey{}, scene)
}
// Scene 返回 ctx 中声明的场景;未声明返回套餐步骤场景。
func Scene(ctx context.Context) string {
if scene, ok := ctx.Value(sceneKey{}).(string); ok && scene != "" {
return scene
}
return constants.StopResumeScenePolling
}
// QueueAware 由停复机服务实现:停复机出口开关开启时请求评估只写共享缓存。
type QueueAware interface {
CommandQueueEnabled(ctx context.Context) bool
}
// RunAfterCommit 在业务事务提交后执行自动停复机请求:开关开启时同步执行(只写共享缓存,不起 goroutine);
// 关闭时沿用旧路径在 goroutine 中当场执行(含网关调用与重试,不阻塞业务流程)。
func RunAfterCommit(ctx context.Context, callback any, fn func()) {
if aware, ok := callback.(QueueAware); ok && aware.CommandQueueEnabled(ctx) {
fn()
return
}
go fn()
}