All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m33s
- 新增网关限流:按本系统运营商账户(卡 carrier_id)→ 限流组 → 操作限制每秒请求数,每次 HTTP 尝试计量,默认限流、仅后台人工点击/通道阈值/自动续费/手动刷新豁免;支持只统计与拦截两种模式,默认只统计 - Asynq 遇限流不计失败、固定短延迟重试;轮询任务与停复机业务重试遇限流短延迟重排 - 停机、复机不再使用网关内部重试,只发一次请求 - 网关返回结构化错误;新增上游错误分类规则表与测试接口 - 新增按月分区的停复机记录表:系统自动停复机只写记录,不再写统一审计与集成日志;普通轮询查询不再写集成日志 - 新增限流组、错误分类、停复机记录、按账户调用统计与枚举后台接口 - 迁移 000243~000246;同步 OpenSpec 提案(含后续 6 个 change)与技术方案、工程约束
59 lines
2.7 KiB
Go
59 lines
2.7 KiB
Go
// Package assetautorenewal 提供资产钱包自动续费的停复机执行适配与异步任务入口。
|
||
package assetautorenewal
|
||
|
||
import (
|
||
"context"
|
||
|
||
assetAutoRenewalApp "github.com/break/junhong_cmp_fiber/internal/application/assetautorenewal"
|
||
"github.com/break/junhong_cmp_fiber/internal/gateway"
|
||
iotCardSvc "github.com/break/junhong_cmp_fiber/internal/service/iot_card"
|
||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||
)
|
||
|
||
// CardCommander 把自动续费复机端口转发到既有停复机单一事实源。
|
||
//
|
||
// 它只做类型与结果分类的转换:判定规则、重试、Integration Log、统一审计与观测序列全部由
|
||
// internal/service/iot_card 提供,本适配器不复制任何规则,也不直接调用运营商接口。
|
||
type CardCommander struct {
|
||
service *iotCardSvc.StopResumeService
|
||
}
|
||
|
||
// NewCardCommander 创建自动续费复机执行适配器。
|
||
func NewCardCommander(service *iotCardSvc.StopResumeService) *CardCommander {
|
||
return &CardCommander{service: service}
|
||
}
|
||
|
||
// AutoRenewalResumeReady 判断该资产是否满足自动复机条件。
|
||
func (c *CardCommander) AutoRenewalResumeReady(ctx context.Context, assetType string, assetID uint) (bool, string, error) {
|
||
if c == nil || c.service == nil {
|
||
return false, "", errCommanderUnavailable()
|
||
}
|
||
return c.service.AutoRenewalResumeReady(ctx, assetType, assetID)
|
||
}
|
||
|
||
// ResumeAssetForAutoRenewal 执行复机并把结果转换为本用例的结果摘要。
|
||
func (c *CardCommander) ResumeAssetForAutoRenewal(ctx context.Context, assetType string, assetID uint) (assetAutoRenewalApp.ResumeOutcome, error) {
|
||
if c == nil || c.service == nil {
|
||
return assetAutoRenewalApp.ResumeOutcome{}, errCommanderUnavailable()
|
||
}
|
||
outcome, err := c.service.ResumeAssetForAutoRenewal(gateway.WithRateLimitExempt(ctx, constants.RateLimitExemptAutoRenewal), assetType, assetID)
|
||
return assetAutoRenewalApp.ResumeOutcome{
|
||
Applied: outcome.Applied, IntegrationID: outcome.IntegrationID,
|
||
Result: outcome.Result, SafeReason: outcome.SafeReason,
|
||
}, err
|
||
}
|
||
|
||
// QueryAutoRenewalResumeState 只查询运营商卡状态,供恢复扫描回填复机结果。
|
||
func (c *CardCommander) QueryAutoRenewalResumeState(ctx context.Context, assetType string, assetID uint) (bool, bool, string, error) {
|
||
if c == nil || c.service == nil {
|
||
return false, false, "", errCommanderUnavailable()
|
||
}
|
||
return c.service.QueryAutoRenewalResumeState(gateway.WithRateLimitExempt(ctx, constants.RateLimitExemptAutoRenewal), assetType, assetID)
|
||
}
|
||
|
||
// errCommanderUnavailable 返回复机执行端口未配置的稳定错误。
|
||
func errCommanderUnavailable() error {
|
||
return errors.New(errors.CodeServiceUnavailable, "自动续费复机执行能力未配置")
|
||
}
|