Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
661eedd62c | ||
|
|
a7817882de | ||
|
|
0550f2ae89 | ||
|
|
5ccca41de6 | ||
|
|
e9b70ead17 | ||
|
|
b499b66a57 |
@@ -2,6 +2,12 @@
|
||||
|
||||
> 本仓 CHANGELOG 自重建起记(POC 明细见归档仓 /data/poc-archive/repos/go-sms.git 的 CHANGELOG.md,已冻结)。
|
||||
|
||||
## 2026-11-13(夜)· S1-B 收口五件 + S1 泳道收官
|
||||
|
||||
- **send P2 拆三子包**(0550f2a):submit/consume/dispatch + facade 别名门面(外部零改动),契约族(事件/状态常量)迁 submit 并导出,依赖单向无环;**dayNN 19 文件语义改名**(5ccca41);**storage minio→s3 归一**(b499b66);**audit_mode=2 文案校准**(「2自动拒绝」→「2自动审核·黑词」,后端 2+openapi 1+前端已对);**gofmt 存量清零**(e9b70ea)。
|
||||
- **S1 泳道出口判定 ✅**:B 层搬运+三项结构改造+迁移链落地+**全仓 -race 38 包 RC=0**+lint 0+集成七件绿;验收单 `docs/acceptance/s1-b-closeout.md`(24h 稳定性门槛在途,11-14 17:55 期满回填)。
|
||||
- 唯一测试适配:clickhouse TestInsertSQL 断言随标识符反引号化更新(非业务语义)。
|
||||
|
||||
## 2026-11-13(晚)· 对象存储 MinIO→RustFS 切换
|
||||
|
||||
- **动因**:MinIO 社区版收费化;**方案=换服务端不换客户端**(minio-go SDK=Apache 2.0 通用 S3 客户端无授权风险)。
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ paths:
|
||||
/accounts/{id}/audit-mode:
|
||||
put:
|
||||
tags: [accounts]
|
||||
summary: 审核模式(0 免审/1 手动/2 自动拒绝)
|
||||
summary: 审核模式(0 免审/1 手动/2 自动审核——黑词命中拒/未命中过)
|
||||
parameters: [{name: id, in: path, required: true, schema: {type: integer}}]
|
||||
requestBody: {content: {application/json: {schema: {type: object, required: [business, mode], properties: {business: {type: string}, mode: {type: integer, enum: [0, 1, 2]}}}}}}
|
||||
responses: {"200": {description: ok}}
|
||||
|
||||
+1
-1
@@ -176,7 +176,7 @@ func main() {
|
||||
submitSvc := send.NewSubmitService(db, sf, reviewSvc, pipelineOpts...)
|
||||
// Day 44:MinIO 对象存储(号码文件);初始化失败降级 nil → /files/numbers/import 不注册。
|
||||
var fileImportSvc *send.FileImportService
|
||||
if mo, merr := storage.NewMinIO(context.Background(),
|
||||
if mo, merr := storage.NewS3(context.Background(),
|
||||
cfg.MinIO.Endpoint, cfg.MinIO.AccessKey, cfg.MinIO.SecretKey, cfg.MinIO.Bucket, cfg.MinIO.UseSSL); merr != nil {
|
||||
a.Lg().Warn("minio_init_failed_file_import_disabled", zap.Error(merr))
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# S1-B 收口 + S1 泳道收官 人工验收单(2026-11-13 晚)
|
||||
|
||||
> 前置:上承 `s1-b-layer-d1.md`(D1+B 层 P1+D5-P1+RustFS+Gitea)。本单覆盖收口五件与 S1 泳道出口判定。
|
||||
|
||||
## 一、收口任务
|
||||
|
||||
| # | 任务 | 结果 | 证据 |
|
||||
|---|---|---|---|
|
||||
| 1 | **send P2 拆三子包**(0550f2a) | ✅ | submit(受理 11 文件+事件/状态契约族)/consume(3)/dispatch(11);根包 facade.go 别名门面 40 符号——**api/openapi/access/report/cmd 调用方零改动**;依赖单向无环;全仓 -race **38 包 RC=0**(router 走 MySQL 硬断言口径) |
|
||||
| 2 | dayNN 语义改名批(5ccca41) | ✅ | 19 文件(api 11/middleware 1/account 5/pool 1/router 1),头注释留 Day 溯源;全仓 `_dayNN_` 模式清零 |
|
||||
| 3 | storage 命名归一(b499b66) | ✅ | minio.go→s3.go/S3Store/NewS3(RustFS Phase C 收口) |
|
||||
| 4 | audit_mode=2 文案校准 | ✅ | 「2自动拒绝」→「2自动审核(黑词命中拒/未命中过)」对齐 audit.ModeAuto 实义;后端 2 处+openapi 1 处+测试措辞;account/audit -race 绿 |
|
||||
| 5 | gofmt 存量清零(e9b70ea) | ✅ | POC 遗留 20 文件全清;`gofmt -l` 全仓零输出 |
|
||||
| 6 | 24h 稳定性门槛 | ⏳ **在途** | 11-13 17:55 起计;至本单时刻:dmesg 崩溃 0、容器重启 0、gateway 驻留;**期满=11-14 17:55,期满核验后本单回填终判** |
|
||||
|
||||
## 二、S1 泳道出口判定(对齐《重建计划》S1 行:「B 层逐域搬运改造+迁移链落地;验收=全包等价 -race 绿」)
|
||||
|
||||
| 出口项 | 判定 |
|
||||
|---|---|
|
||||
| B 层逐域搬运改造 | ✅ 12 域 P1 全量 + send 拆包/channel 拆 pool/router 空壳消除 三项结构改造完成,dayNN 清零 |
|
||||
| 迁移链 v1~v19 落地 | ✅ 空库独建+seed-admin(D1) |
|
||||
| 全包等价 -race 绿 | ✅ **38 包 RC=0**(两阶段等价法全程可审计;唯一测试改动=clickhouse TestInsertSQL 断言随标识符反引号化更新+测试 helper 本地化,均非业务语义) |
|
||||
| lint | ✅ v2.1.6 全仓 0 告警 |
|
||||
| 集成测试 | ✅ 七件绿(storage 新增) |
|
||||
| 附加 | gateway :8081 装配冒烟驻留;Gitea 远端同步;RustFS 对象存储就位 |
|
||||
|
||||
**S1 泳道状态:✅ 收官(附一项在途观察:24h 门槛,11-14 17:55 期满回填)。**
|
||||
|
||||
## 三、遗留移交(不阻塞 S2)
|
||||
|
||||
1. 24h 门槛期满核验(明日)→ 本单回填 + S5 压测基线资格确认;
|
||||
2. FE 侧(views 31 页/FE-6/node 工具链)= S3 泳道;
|
||||
3. C1 回调引擎 = S4;结算域 = S2(下一泳道)。
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// account_day29_test.go Day 29:审计查询 API(system:read 门禁)+ 拦截器联动。
|
||||
// account_audit_query_test.go(原 Day29):审计查询 API(system:read 门禁)+ 拦截器联动。
|
||||
package v1
|
||||
|
||||
import (
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// account_day25_test.go Day 25 验收:普通账号访问 /accounts/export 返回 403,
|
||||
// account_export_permission_test.go(原 Day25)验收:普通账号访问 /accounts/export 返回 403,
|
||||
// admin 可正常导出;二级权限授予后即时放行、撤销后收回。
|
||||
package v1
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// account_day28_test.go Day 28:上级切换/标星/团队/实名的 API 权限与闭环。
|
||||
// account_hierarchy_realname_test.go(原 Day28):上级切换/标星/团队/实名的 API 权限与闭环。
|
||||
package v1
|
||||
|
||||
import (
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// account_day30_test.go Day 30:阶段 2 验收全量回归(A-2.1~A-2.13)。
|
||||
// account_phase2_regression_test.go(原 Day30):阶段 2 验收全量回归(A-2.1~A-2.13)。
|
||||
// 以真实 HTTP 请求串联全部端点,等价 Postman 集合;证据映射见 docs/phase2-review.md。
|
||||
package v1
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// account_day26_test.go Day 26 验收:充值二级权限门禁 / 批量 CSV / 余额越权。
|
||||
// account_recharge_permission_test.go(原 Day26)验收:充值二级权限门禁 / 批量 CSV / 余额越权。
|
||||
// 复用 newD25Router(admin=1 通配,customer=2;Register 已含 Day 26 路由)。
|
||||
package v1
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// account_day27_test.go Day 27:预警配置端点(本人/admin 读写、越权 403)。
|
||||
// account_warning_config_test.go(原 Day27):预警配置端点(本人/admin 读写、越权 403)。
|
||||
package v1
|
||||
|
||||
import (
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// channel_day35_test.go Day 35:通道路由——CRUD/测试工具/拦截(channel:write 门禁)。
|
||||
// channel_crud_route_test.go(原 Day35):通道路由——CRUD/测试工具/拦截(channel:write 门禁)。
|
||||
package v1
|
||||
|
||||
import (
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// channel_day39_test.go Day 39:链路状态/回执复核端点(发送真实性 WEB 验收)。
|
||||
// channel_link_receipts_test.go(原 Day39):链路状态/回执复核端点(发送真实性 WEB 验收)。
|
||||
package v1
|
||||
|
||||
import (
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// channel_day40_test.go Day 40:监控快照/WS 升级/通道日志端点(A-3.13/A-3.14 WEB 验收)。
|
||||
// channel_monitor_logs_test.go(原 Day40):监控快照/WS 升级/通道日志端点(A-3.13/A-3.14 WEB 验收)。
|
||||
package v1
|
||||
|
||||
import (
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// send_day42_test.go Day 42:/send/precheck 预检端点——拦截器链真入口(D18 提交前预检)。
|
||||
// send_precheck_test.go(原 Day42):/send/precheck 预检端点——拦截器链真入口(D18 提交前预检)。
|
||||
package v1
|
||||
|
||||
import (
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// template_day41_test.go Day 41:模板 CRUD/审核状态机/发送预估端点(阶段 4 开篇)。
|
||||
// template_lifecycle_test.go(原 Day41):模板 CRUD/审核状态机/发送预估端点(阶段 4 开篇)。
|
||||
package v1
|
||||
|
||||
import (
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// auth_day24_test.go Day 24:黑名单鉴权中间件测试。
|
||||
// auth_jwt_revocation_test.go(原 Day24):黑名单鉴权中间件测试。
|
||||
package middleware
|
||||
|
||||
import (
|
||||
@@ -1,4 +1,4 @@
|
||||
// Package storage Day 44:对象存储(MinIO,S3 API)——号码文件/报表/检测结果落桶。
|
||||
// Package storage Day 44:对象存储(S3 API;2026-11-13 起后端=RustFS,客户端=minio-go 通用 S3 SDK)——号码文件/报表/检测结果落桶。
|
||||
// 最小接口 ObjectStore 供服务层依赖倒置(测试用内存实现,见 fileimport_test)。
|
||||
package storage
|
||||
|
||||
@@ -17,14 +17,14 @@ type ObjectStore interface {
|
||||
Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error
|
||||
}
|
||||
|
||||
// MinIOStore minio-go 实现(启动时 EnsureBucket)。
|
||||
type MinIOStore struct {
|
||||
// S3Store minio-go 实现(启动时 EnsureBucket)。
|
||||
type S3Store struct {
|
||||
cli *minio.Client
|
||||
bucket string
|
||||
}
|
||||
|
||||
// NewMinIO 按配置建客户端并确保桶存在(幂等)。
|
||||
func NewMinIO(ctx context.Context, endpoint, accessKey, secretKey, bucket string, useSSL bool) (*MinIOStore, error) {
|
||||
// NewS3 按配置建客户端并确保桶存在(幂等)。
|
||||
func NewS3(ctx context.Context, endpoint, accessKey, secretKey, bucket string, useSSL bool) (*S3Store, error) {
|
||||
cli, err := minio.New(endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(accessKey, secretKey, ""),
|
||||
Secure: useSSL,
|
||||
@@ -41,11 +41,11 @@ func NewMinIO(ctx context.Context, endpoint, accessKey, secretKey, bucket string
|
||||
return nil, fmt.Errorf("storage: make bucket %s: %w", bucket, err)
|
||||
}
|
||||
}
|
||||
return &MinIOStore{cli: cli, bucket: bucket}, nil
|
||||
return &S3Store{cli: cli, bucket: bucket}, nil
|
||||
}
|
||||
|
||||
// Put 实现 ObjectStore。
|
||||
func (s *MinIOStore) Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error {
|
||||
func (s *S3Store) Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error {
|
||||
if contentType == "" {
|
||||
contentType = "application/octet-stream"
|
||||
}
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestInsertSQL 验证语句构造。
|
||||
// TestInsertSQL 验证语句构造(S1-B:标识符反引号化,兼容含连字符表名)。
|
||||
func TestInsertSQL(t *testing.T) {
|
||||
if got := insertSQL("mt", []string{"id", "mobile"}); got != "INSERT INTO mt (id,mobile)" {
|
||||
if got := insertSQL("mt", []string{"id", "mobile"}); got != "INSERT INTO `mt` (`id`,`mobile`)" {
|
||||
t.Errorf("insertSQL = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,10 +85,10 @@ func IPAllowed(ipBindJSON, clientIP string) bool {
|
||||
|
||||
// ---- 审核模式 ----
|
||||
|
||||
// SetAuditMode 设置审核模式(0免审/1手动/2自动拒绝)。
|
||||
// SetAuditMode 设置审核模式(0免审/1手动/2自动审核——黑词命中拒/未命中过,对齐 audit.ModeAuto 口径)。
|
||||
func (s *Service) SetAuditMode(ctx context.Context, accountID int64, business string, mode int) error {
|
||||
if mode < 0 || mode > 2 {
|
||||
return errs.InvalidParam.WithMsg(fmt.Sprintf("非法审核模式 %d(0免审/1手动/2自动拒绝)", mode))
|
||||
return errs.InvalidParam.WithMsg(fmt.Sprintf("非法审核模式 %d(0免审/1手动/2自动审核·黑词)", mode))
|
||||
}
|
||||
result := s.config.DB().WithContext(ctx).Model(&entity.AccountConfig{}).
|
||||
Where("account_id = ? AND business = ?", accountID, business).
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// service_day25_test.go Day 25:Casbin 策略同步(开户绑定/改角重绑/删除解绑)+ 二级权限。
|
||||
// service_casbin_sync_test.go(原 Day25):Casbin 策略同步(开户绑定/改角重绑/删除解绑)+ 二级权限。
|
||||
package account
|
||||
|
||||
import (
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// service_day29_test.go Day 29:覆盖率补齐——存量路径重建/nil 引擎降级/默认构造分支。
|
||||
// service_coverage_legacy_test.go(原 Day29):覆盖率补齐——存量路径重建/nil 引擎降级/默认构造分支。
|
||||
package account
|
||||
|
||||
import (
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// service_day28_test.go Day 28:上级切换(级联路径+防环)/标星置顶/服务团队/实名状态机。
|
||||
// service_hierarchy_test.go(原 Day28):上级切换(级联路径+防环)/标星置顶/服务团队/实名状态机。
|
||||
package account
|
||||
|
||||
import (
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// service_day26_test.go Day 26:充值(单笔/批量)+ 余额查询。
|
||||
// service_recharge_test.go(原 Day26):充值(单笔/批量)+ 余额查询。
|
||||
// 验收锚点:充值即余额+流水一致(事务);批量行级报错定位。
|
||||
package account
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// service_day27_test.go Day 27:余额预警——阈值触发/冷却去重/可用额度/停用跳过/配置 upsert。
|
||||
// service_warning_test.go(原 Day27):余额预警——阈值触发/冷却去重/可用额度/停用跳过/配置 upsert。
|
||||
package account
|
||||
|
||||
import (
|
||||
@@ -107,7 +107,7 @@ func TestRouteModes(t *testing.T) {
|
||||
t4 := mkTask(t, db, 3, "低价代开发票")
|
||||
task, rec, err = s.Route(ctx, t4.ID)
|
||||
if err != nil || task.AuditStatus != AuditRejected || rec == nil {
|
||||
t.Fatalf("自动拒绝 got status=%d err=%v", task.AuditStatus, err)
|
||||
t.Fatalf("自动档黑词拒绝 got status=%d err=%v", task.AuditStatus, err)
|
||||
}
|
||||
if rec.Reason != "命中敏感词: 发票" {
|
||||
t.Fatalf("拒绝留痕应含命中词, got %q", rec.Reason)
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// link_day40_test.go Day 40(A-3.5):真网断线重连演练——网关进程消失→心跳断链→
|
||||
// link_reconnect_drill_test.go(原 Day40 A-3.5):真网断线重连演练——网关进程消失→心跳断链→
|
||||
// 同端口复活→指数退避重连→提交恢复。断言全程远小于 30s 重连上限,并留痕 channel_log。
|
||||
package pool_test
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// router_day40_test.go Day 40:千条/秒路由压测(验收:1000 条/秒稳定,单次决策 <10ms)。
|
||||
// router_1000qps_test.go(原 Day40):千条/秒路由压测(验收:1000 条/秒稳定,单次决策 <10ms)。
|
||||
// 8 并发 × 125 次 = 1000 次 Pick(权重+过滤全链路),统计 p50/p99/吞吐。
|
||||
package router
|
||||
|
||||
@@ -6,13 +6,15 @@
|
||||
// 顺带修复"手动审核通过后任务停滞"缺陷);
|
||||
// - 分发复用 ChannelDispatcher(router 选路→聚合/直发链路→明细终态);
|
||||
// 系统性错误回滚 status 1→0 留待重扫(claim 原子性保证重试幂等)。
|
||||
package send
|
||||
package consume
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go-sms/internal/service/send/dispatch"
|
||||
"go-sms/internal/service/send/submit"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -26,64 +28,15 @@ import (
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
// SubmitEvent sms-submit 事件载荷(Day46 openapi 五字段向后兼容+Day48 扩展+Day52 R2 明细全量)。
|
||||
type SubmitEvent struct {
|
||||
TaskID int64 `json:"task_id"`
|
||||
TaskNo string `json:"task_no"`
|
||||
AccountID int64 `json:"account_id"`
|
||||
SendType int8 `json:"send_type"`
|
||||
PassCount int `json:"pass_count"` // 过拦截条数(0=全拦,消费者跳过;Day52 起由 details 推导)
|
||||
Source string `json:"source"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
Business string `json:"business,omitempty"` // Day 49:sms/video(biz_type 路由;空=sms 兼容 Day48 旧载荷)
|
||||
// Day52 R2:明细全量(入口预生成雪花 ID+拦截终态;消费侧批量落库,入口事务零明细写)。
|
||||
// 空=Day48 旧格式/兜底扫描场景,消费侧不落(明细已由降级路径或旧版本落库)。
|
||||
Details []EventDetail `json:"details,omitempty"`
|
||||
// P0-1(Day 63)接入异步化:Deferred=true 表示受理侧走 SubmitFast 快路径
|
||||
// (Validate+预扣+DetailID 预生成+投递,零 DB 写),task 落库/拦截判定/退费/
|
||||
// 审核分流全部由消费侧补全(handleDeferred);TaskID=0(自增主键消费侧生成)。
|
||||
Deferred bool `json:"deferred,omitempty"`
|
||||
// TaskMeta Deferred 专用:任务行补建字段(与 entity.MessageTask 对齐;
|
||||
// 旧事件零携带,消费侧按非 Deferred 老路径处理)。
|
||||
TaskMeta *SubmitTaskMeta `json:"task_meta,omitempty"`
|
||||
}
|
||||
|
||||
// SubmitTaskMeta 快路径任务补建载荷(受理侧未落库,消费侧 INSERT 重建)。
|
||||
type SubmitTaskMeta struct {
|
||||
Content string `json:"content"`
|
||||
Sign string `json:"sign"`
|
||||
MobileCount int `json:"mobile_count"`
|
||||
FeeTotal float64 `json:"fee_total"`
|
||||
SubmitIP string `json:"submit_ip"`
|
||||
CallData string `json:"call_data"`
|
||||
Source int8 `json:"source"` // 任务来源 int8(WEB=4/CMPP=2/SMPP=3/API=1)
|
||||
ScheduleAt string `json:"schedule_at,omitempty"` // RFC3339,空=非定时
|
||||
}
|
||||
|
||||
// EventDetail 明细行载荷(task_id/account_id 公共字段在事件级;字段与 entity.MessageDetail 对齐)。
|
||||
type EventDetail struct {
|
||||
ID int64 `json:"id"` // 雪花主键(入口预生成,回执配对键)
|
||||
Mobile string `json:"mobile"`
|
||||
Content string `json:"content"`
|
||||
Status int8 `json:"status"` // 0=存活 5=拦截终态(受理期已退费)
|
||||
Fee float64 `json:"fee"` // 计费条数
|
||||
ErrorCode string `json:"error_code,omitempty"`
|
||||
ExtCode string `json:"ext_code,omitempty"`
|
||||
CallData string `json:"call_data,omitempty"`
|
||||
// Day66:明细单表化冗余(空=旧载荷,persistDetailsDB 兜底 ev.Business/'sms')。
|
||||
Business string `json:"business,omitempty"`
|
||||
Source int8 `json:"source,omitempty"` // 0=旧载荷→兜底 API
|
||||
}
|
||||
|
||||
// SubmitConsumer 事件消费者。
|
||||
type SubmitConsumer struct {
|
||||
db *gorm.DB
|
||||
dp TaskDispatcher
|
||||
dp dispatch.TaskDispatcher
|
||||
log *zap.Logger
|
||||
blocked BlockedDeliverSink // Day62c:拦截终态 CMPP 下发出口(nil=静默)
|
||||
// P0-1(Day 63)Deferred 补全依赖(受理快路径的同步链后移;nil=对应环节降级)。
|
||||
chain *interceptor.Chain // 拦截器链(nil=全放行,兼容最小装配)
|
||||
rt TaskRouter // 审核分流(nil=停留待审,48h Scanner 兜底)
|
||||
rt submit.TaskRouter // 审核分流(nil=停留待审,48h Scanner 兜底)
|
||||
bal balance.Store // 拦截/审核拒退费(nil=不退,对账 Reconciler 兜底)
|
||||
}
|
||||
|
||||
@@ -109,7 +62,7 @@ func (c *SubmitConsumer) WithConsumerChain(ch *interceptor.Chain) *SubmitConsume
|
||||
}
|
||||
|
||||
// WithConsumerRouter 注入审核分流(P0-1 Deferred 补全;链式)。
|
||||
func (c *SubmitConsumer) WithConsumerRouter(rt TaskRouter) *SubmitConsumer {
|
||||
func (c *SubmitConsumer) WithConsumerRouter(rt submit.TaskRouter) *SubmitConsumer {
|
||||
c.rt = rt
|
||||
return c
|
||||
}
|
||||
@@ -121,7 +74,7 @@ func (c *SubmitConsumer) WithConsumerBalance(b balance.Store) *SubmitConsumer {
|
||||
}
|
||||
|
||||
// NewSubmitConsumer 构造。
|
||||
func NewSubmitConsumer(db *gorm.DB, dp TaskDispatcher, log *zap.Logger) *SubmitConsumer {
|
||||
func NewSubmitConsumer(db *gorm.DB, dp dispatch.TaskDispatcher, log *zap.Logger) *SubmitConsumer {
|
||||
if log == nil {
|
||||
log = zap.NewNop()
|
||||
}
|
||||
@@ -133,7 +86,7 @@ func NewSubmitConsumer(db *gorm.DB, dp TaskDispatcher, log *zap.Logger) *SubmitC
|
||||
// Day52 R2:明细批量落库先于认领/下发(回执配对键先于 submit 存在;
|
||||
// 雪花主键冲突 DoNothing=重投幂等;失败返回错误进重试——明细为对账事实源不能丢)。
|
||||
func (c *SubmitConsumer) HandlePayload(ctx context.Context, payload []byte) error {
|
||||
var ev SubmitEvent
|
||||
var ev submit.SubmitEvent
|
||||
if err := json.Unmarshal(payload, &ev); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -161,7 +114,7 @@ func (c *SubmitConsumer) HandlePayload(ctx context.Context, payload []byte) erro
|
||||
// ①拦截器链判定(命中→明细终态 5+拦截费退)②task INSERT 补建(uk_task_no
|
||||
// 冲突=重投幂等:查回既有 ID,退费仅首次执行)③明细落库+拦截回执桥(Day62c)
|
||||
// ④全拦→任务终态 ⑤审核分流(拒绝→存活费退)⑥claim/dispatch(待审/定时自然跳过)。
|
||||
func (c *SubmitConsumer) handleDeferred(ctx context.Context, ev *SubmitEvent) error {
|
||||
func (c *SubmitConsumer) handleDeferred(ctx context.Context, ev *submit.SubmitEvent) error {
|
||||
if len(ev.Details) == 0 || ev.TaskMeta == nil {
|
||||
return nil // 防御:Deferred 事件必带明细与任务载荷(缺失静默,防毒丸循环重试)
|
||||
}
|
||||
@@ -248,7 +201,7 @@ func (c *SubmitConsumer) handleDeferred(ctx context.Context, ev *SubmitEvent) er
|
||||
_ = c.db.WithContext(ctx).Model(&entity.MessageTask{}).
|
||||
Where("id = ? AND status = ?", task.ID, 0).
|
||||
Updates(map[string]any{
|
||||
"status": taskStDone, "fail_count": len(ev.Details), "finished_at": time.Now(),
|
||||
"status": submit.TaskStDone, "fail_count": len(ev.Details), "finished_at": time.Now(),
|
||||
}).Error
|
||||
return nil
|
||||
}
|
||||
@@ -282,7 +235,7 @@ func isDupTaskNo(err error) bool {
|
||||
// (status=5)且 task.source=CMPP 逐条推送下发事件——拦截明细无上游回执可等,
|
||||
// 不推则 CMPP 客户永远收不到状态(真机报障实证)。
|
||||
// Day65:内核拆出 persistDetailsDB(exec)——deferred 路径与任务补建同事务执行。
|
||||
func (c *SubmitConsumer) persistDetails(ctx context.Context, ev *SubmitEvent) error {
|
||||
func (c *SubmitConsumer) persistDetails(ctx context.Context, ev *submit.SubmitEvent) error {
|
||||
inserted, err := persistDetailsDB(c.db.WithContext(ctx), ctx, ev)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -293,7 +246,7 @@ func (c *SubmitConsumer) persistDetails(ctx context.Context, ev *SubmitEvent) er
|
||||
|
||||
// persistDetailsDB 明细批量落库(exec=连接或事务;返回本轮实际插入行数——
|
||||
// 重投幂等锚=雪花主键 OnConflict DoNothing)。
|
||||
func persistDetailsDB(exec *gorm.DB, ctx context.Context, ev *SubmitEvent) (int64, error) {
|
||||
func persistDetailsDB(exec *gorm.DB, ctx context.Context, ev *submit.SubmitEvent) (int64, error) {
|
||||
if len(ev.Details) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
@@ -310,7 +263,7 @@ func persistDetailsDB(exec *gorm.DB, ctx context.Context, ev *SubmitEvent) (int6
|
||||
}
|
||||
}
|
||||
if src == 0 {
|
||||
src = TaskSourceAPI
|
||||
src = submit.TaskSourceAPI
|
||||
}
|
||||
rows = append(rows, entity.MessageDetail{
|
||||
SnowflakeModel: entity.SnowflakeModel{ID: d.ID},
|
||||
@@ -338,7 +291,7 @@ func persistDetailsDB(exec *gorm.DB, ctx context.Context, ev *SubmitEvent) (int6
|
||||
|
||||
// pushBlocked 拦截终态下发(Day62c):本轮新插入才推(RowsAffected=0=纯重投跳过;
|
||||
// 批内混合插入的极端重投重复可容忍,客户端按 Stat 幂等处理)。
|
||||
func (c *SubmitConsumer) pushBlocked(ctx context.Context, ev *SubmitEvent, inserted int64) {
|
||||
func (c *SubmitConsumer) pushBlocked(ctx context.Context, ev *submit.SubmitEvent, inserted int64) {
|
||||
if c.blocked == nil || inserted == 0 {
|
||||
return
|
||||
}
|
||||
@@ -361,7 +314,7 @@ func (c *SubmitConsumer) pushBlocked(ctx context.Context, ev *SubmitEvent, inser
|
||||
zap.Int64("task_id", ev.TaskID), zap.Error(err))
|
||||
return
|
||||
}
|
||||
if source != TaskSourceCMPP {
|
||||
if source != submit.TaskSourceCMPP {
|
||||
return // HTTP/控制台/SMPP 来源无 CMPP 会话诉求(SMPP 下发另立项)
|
||||
}
|
||||
submitAt := time.Now().Format("0102150405") // CMPP MMDDHHMMSS
|
||||
@@ -378,7 +331,7 @@ func (c *SubmitConsumer) pushBlocked(ctx context.Context, ev *SubmitEvent, inser
|
||||
func (c *SubmitConsumer) claim(ctx context.Context, id int64) bool {
|
||||
res := c.db.WithContext(ctx).Model(&entity.MessageTask{}).
|
||||
Where("id = ? AND status = 0 AND audit_status IN (1, 3) AND send_type IN (1, 2)", id).
|
||||
Update("status", taskStSending)
|
||||
Update("status", submit.TaskStSending)
|
||||
return res.RowsAffected == 1
|
||||
}
|
||||
|
||||
@@ -393,12 +346,12 @@ func (c *SubmitConsumer) dispatch(ctx context.Context, id int64) error {
|
||||
// Day62d:陈年孤儿任务(旧格式无明细,事件永不再来)一次性终态结案——
|
||||
// 否则 ReclaimScanner 5s/轮死循环重试(dev 实证 task 343 刷 warn 两日)。
|
||||
// 1h 宽限覆盖 Day52 事件在途窗口;正常任务明细早已落库。
|
||||
if errors.Is(derr, ErrDetailsNotReady) && time.Since(task.CreatedAt) > time.Hour {
|
||||
if errors.Is(derr, dispatch.ErrDetailsNotReady) && time.Since(task.CreatedAt) > time.Hour {
|
||||
c.log.Warn("orphan_task_finalized",
|
||||
zap.Int64("task_id", id), zap.Time("created_at", task.CreatedAt))
|
||||
res := c.db.WithContext(ctx).Model(&entity.MessageTask{}).
|
||||
Where("id = ? AND status = ?", id, taskStSending).
|
||||
Updates(map[string]any{"status": taskStDone, "finished_at": time.Now()})
|
||||
Where("id = ? AND status = ?", id, submit.TaskStSending).
|
||||
Updates(map[string]any{"status": submit.TaskStDone, "finished_at": time.Now()})
|
||||
if res.Error == nil && res.RowsAffected > 0 {
|
||||
return nil
|
||||
}
|
||||
@@ -407,9 +360,9 @@ func (c *SubmitConsumer) dispatch(ctx context.Context, id int64) error {
|
||||
return c.rollback(ctx, id)
|
||||
}
|
||||
res := c.db.WithContext(ctx).Model(&entity.MessageTask{}).
|
||||
Where("id = ? AND status = ?", id, taskStSending).
|
||||
Where("id = ? AND status = ?", id, submit.TaskStSending).
|
||||
Updates(map[string]any{
|
||||
"status": taskStDone, "success_count": sent, "fail_count": failed,
|
||||
"status": submit.TaskStDone, "success_count": sent, "fail_count": failed,
|
||||
"finished_at": time.Now(),
|
||||
})
|
||||
if res.Error != nil || res.RowsAffected == 0 {
|
||||
@@ -421,7 +374,7 @@ func (c *SubmitConsumer) dispatch(ctx context.Context, id int64) error {
|
||||
// rollback 认领回退(status 1→0,下轮重扫;幂等由 claim 保证)。
|
||||
func (c *SubmitConsumer) rollback(ctx context.Context, id int64) error {
|
||||
return c.db.WithContext(ctx).Model(&entity.MessageTask{}).
|
||||
Where("id = ? AND status = ?", id, taskStSending).
|
||||
Where("id = ? AND status = ?", id, submit.TaskStSending).
|
||||
Update("status", 0).Error
|
||||
}
|
||||
|
||||
@@ -433,7 +386,7 @@ type ReclaimScanner struct {
|
||||
}
|
||||
|
||||
// NewReclaimScanner 构造。
|
||||
func NewReclaimScanner(db *gorm.DB, dp TaskDispatcher, log *zap.Logger) *ReclaimScanner {
|
||||
func NewReclaimScanner(db *gorm.DB, dp dispatch.TaskDispatcher, log *zap.Logger) *ReclaimScanner {
|
||||
return &ReclaimScanner{db: db, sc: NewSubmitConsumer(db, dp, log), batch: 100}
|
||||
}
|
||||
|
||||
+18
-16
@@ -1,6 +1,6 @@
|
||||
// consumer_test.go Day 48:submit 消费者单测——事件认领分发终态/幂等重投/
|
||||
// 定时域不认领/补偿扫描(审核通过即发)/毒丸载荷回死信口径。
|
||||
package send
|
||||
package consume
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"time"
|
||||
|
||||
"go-sms/internal/model/entity"
|
||||
"go-sms/internal/service/send/dispatch"
|
||||
"go-sms/internal/service/send/submit"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
@@ -40,7 +42,7 @@ func mkImmediateTask(t *testing.T, db *gorm.DB, audit int8, sendType int8) *enti
|
||||
|
||||
func evPayload(t *testing.T, task *entity.MessageTask, pass int) []byte {
|
||||
t.Helper()
|
||||
b, err := json.Marshal(SubmitEvent{TaskID: task.ID, TaskNo: task.TaskNo,
|
||||
b, err := json.Marshal(submit.SubmitEvent{TaskID: task.ID, TaskNo: task.TaskNo,
|
||||
AccountID: task.AccountID, SendType: task.SendType, PassCount: pass})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -86,7 +88,7 @@ func TestConsumerIdempotentReplay(t *testing.T) {
|
||||
// TestConsumerSkipDomains 域过滤:定时(3)/待审(audit=0)不认领。
|
||||
func TestConsumerSkipDomains(t *testing.T) {
|
||||
db := newTimerDB(t)
|
||||
timerTask := mkImmediateTask(t, db, 3, SendTypeTimer)
|
||||
timerTask := mkImmediateTask(t, db, 3, submit.SendTypeTimer)
|
||||
pending := mkImmediateTask(t, db, 0, 1)
|
||||
dp := &fakeDispatcher{}
|
||||
sc := NewSubmitConsumer(db, dp, zap.NewNop())
|
||||
@@ -178,11 +180,11 @@ func TestConsumerPersistDetailsIdempotent(t *testing.T) {
|
||||
if err := db.Create(task).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dets := []EventDetail{
|
||||
dets := []submit.EventDetail{
|
||||
{ID: 9200000001, Mobile: "13800138000", Content: "【店】测试", Fee: 1},
|
||||
{ID: 9200000002, Mobile: "13800138001", Content: "【店】测试", Fee: 1},
|
||||
}
|
||||
b, err := json.Marshal(SubmitEvent{TaskID: task.ID, TaskNo: task.TaskNo,
|
||||
b, err := json.Marshal(submit.SubmitEvent{TaskID: task.ID, TaskNo: task.TaskNo,
|
||||
AccountID: task.AccountID, SendType: 1, PassCount: 2, Details: dets})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -227,9 +229,9 @@ func TestConsumerBlockedDeliver(t *testing.T) {
|
||||
source int8
|
||||
want int
|
||||
}{
|
||||
{TaskSourceCMPP, 2}, // CMPP:2 条拦截行各 1 次
|
||||
{TaskSourceAPI, 0}, // API 来源:不下发
|
||||
{TaskSourceWeb, 0}, // 控制台来源:不下发
|
||||
{submit.TaskSourceCMPP, 2}, // CMPP:2 条拦截行各 1 次
|
||||
{submit.TaskSourceAPI, 0}, // API 来源:不下发
|
||||
{submit.TaskSourceWeb, 0}, // 控制台来源:不下发
|
||||
} {
|
||||
db := newTimerDB(t)
|
||||
task := &entity.MessageTask{
|
||||
@@ -240,14 +242,14 @@ func TestConsumerBlockedDeliver(t *testing.T) {
|
||||
if err := db.Create(task).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
dets := []EventDetail{
|
||||
dets := []submit.EventDetail{
|
||||
{ID: 9300000001, Mobile: "13800138000", Content: task.Content, Fee: 1}, // 存活
|
||||
{ID: 9300000002, Mobile: "13800138001", Content: task.Content, Status: 5,
|
||||
ErrorCode: "ISC:004"}, // 拦截(签名)
|
||||
{ID: 9300000003, Mobile: "13800138002", Content: task.Content, Status: 5,
|
||||
ErrorCode: "ISC:009"}, // 拦截(其他码)
|
||||
}
|
||||
b, err := json.Marshal(SubmitEvent{TaskID: task.ID, TaskNo: task.TaskNo,
|
||||
b, err := json.Marshal(submit.SubmitEvent{TaskID: task.ID, TaskNo: task.TaskNo,
|
||||
AccountID: task.AccountID, SendType: 1, PassCount: 1, Details: dets})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -292,7 +294,7 @@ func TestOrphanTaskFinalized(t *testing.T) {
|
||||
return task
|
||||
}
|
||||
old, fresh := mk(-2*time.Hour), mk(-time.Minute)
|
||||
dp := &fakeDispatcher{err: ErrDetailsNotReady} // 明细缺失(事件在途/孤儿)
|
||||
dp := &fakeDispatcher{err: dispatch.ErrDetailsNotReady} // 明细缺失(事件在途/孤儿)
|
||||
rs := NewReclaimScanner(db, dp, zap.NewNop()).WithBatch(10)
|
||||
for i := 0; i < 2; i++ { // 两轮扫描:孤儿首轮结案;新任务始终回滚
|
||||
if _, _, err := rs.ScanOnce(context.Background()); err != nil {
|
||||
@@ -303,7 +305,7 @@ func TestOrphanTaskFinalized(t *testing.T) {
|
||||
if err := db.First(&got, old.ID).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.Status != taskStDone || got.FinishedAt.IsZero() {
|
||||
if got.Status != submit.TaskStDone || got.FinishedAt.IsZero() {
|
||||
t.Fatalf("孤儿任务应终态结案: status=%d finished_at=%v", got.Status, got.FinishedAt)
|
||||
}
|
||||
var freshGot entity.MessageTask
|
||||
@@ -321,15 +323,15 @@ func TestConsumerTimerEventPersistOnly(t *testing.T) {
|
||||
db := newTimerDB(t)
|
||||
task := &entity.MessageTask{
|
||||
TaskNo: "CS" + time.Now().Format("150405.000000001"), AccountID: 1001,
|
||||
SendType: SendTypeTimer, Content: "【店】定时", Sign: "店",
|
||||
SendType: submit.SendTypeTimer, Content: "【店】定时", Sign: "店",
|
||||
MobileCount: 1, AuditStatus: 3, Status: 0,
|
||||
}
|
||||
if err := db.Create(task).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b, err := json.Marshal(SubmitEvent{TaskID: task.ID, TaskNo: task.TaskNo,
|
||||
AccountID: task.AccountID, SendType: SendTypeTimer, PassCount: 1,
|
||||
Details: []EventDetail{{ID: 9200000003, Mobile: "13800138000", Content: "【店】定时", Fee: 1}}})
|
||||
b, err := json.Marshal(submit.SubmitEvent{TaskID: task.ID, TaskNo: task.TaskNo,
|
||||
AccountID: task.AccountID, SendType: submit.SendTypeTimer, PassCount: 1,
|
||||
Details: []submit.EventDetail{{ID: 9200000003, Mobile: "13800138000", Content: "【店】定时", Fee: 1}}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
+17
-16
@@ -1,11 +1,12 @@
|
||||
// deferred_test.go P0-1(Day 63)接入异步化——SubmitFast 快路径(零 DB 写+
|
||||
// deferred_test.go P0-1(Day 63)接入异步化——submit.SubmitFast 快路径(零 DB 写+
|
||||
// MsgID=DetailID 口径)+handleDeferred 消费侧补全(建任务/拦截终态/退费/
|
||||
// 全拦终态/claim 幂等)。
|
||||
package send
|
||||
package consume
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"go-sms/internal/service/send/submit"
|
||||
"testing"
|
||||
|
||||
"go-sms/internal/model/entity"
|
||||
@@ -52,13 +53,13 @@ func TestSubmitFastEmit(t *testing.T) {
|
||||
db := newTimerDB(t)
|
||||
sf, _ := util.NewSnowflake(9)
|
||||
fb, sink := &fakeBal{}, &captureSink{}
|
||||
svc := NewSubmitService(db, sf, nil, WithBalanceStore(fb), WithEventSink(sink))
|
||||
svc := submit.NewSubmitService(db, sf, nil, submit.WithBalanceStore(fb), submit.WithEventSink(sink))
|
||||
|
||||
req := &SubmitReq{AccountID: 1001, SendType: SendTypeBatch,
|
||||
Mobiles: []string{"13800138000"}, Content: "【梦网】验证码", Source: TaskSourceCMPP}
|
||||
req := &submit.SubmitReq{AccountID: 1001, SendType: submit.SendTypeBatch,
|
||||
Mobiles: []string{"13800138000"}, Content: "【梦网】验证码", Source: submit.TaskSourceCMPP}
|
||||
res, err := svc.SubmitFast(context.Background(), req, req.Content, "1.2.3.4")
|
||||
if err != nil {
|
||||
t.Fatalf("SubmitFast err=%v", err)
|
||||
t.Fatalf("submit.SubmitFast err=%v", err)
|
||||
}
|
||||
if len(fb.holds) != 1 {
|
||||
t.Fatalf("Hold 调用 %d 次,期望 1", len(fb.holds))
|
||||
@@ -84,17 +85,17 @@ func TestSubmitFastEmit(t *testing.T) {
|
||||
func TestSubmitFastFail(t *testing.T) {
|
||||
db := newTimerDB(t)
|
||||
sf, _ := util.NewSnowflake(9)
|
||||
req := &SubmitReq{AccountID: 1001, SendType: SendTypeBatch,
|
||||
req := &submit.SubmitReq{AccountID: 1001, SendType: submit.SendTypeBatch,
|
||||
Mobiles: []string{"13800138000"}, Content: "【梦网】x"}
|
||||
|
||||
fb := &fakeBal{failHold: true}
|
||||
svc := NewSubmitService(db, sf, nil, WithBalanceStore(fb), WithEventSink(&captureSink{}))
|
||||
svc := submit.NewSubmitService(db, sf, nil, submit.WithBalanceStore(fb), submit.WithEventSink(&captureSink{}))
|
||||
if _, err := svc.SubmitFast(context.Background(), req, req.Content, ""); err == nil {
|
||||
t.Fatal("欠费应同步拒绝")
|
||||
}
|
||||
|
||||
fb2 := &fakeBal{}
|
||||
svc2 := NewSubmitService(db, sf, nil, WithBalanceStore(fb2), WithEventSink(failSink{}))
|
||||
svc2 := submit.NewSubmitService(db, sf, nil, submit.WithBalanceStore(fb2), submit.WithEventSink(failSink{}))
|
||||
if _, err := svc2.SubmitFast(context.Background(), req, req.Content, ""); err == nil {
|
||||
t.Fatal("投递失败应拒绝")
|
||||
}
|
||||
@@ -106,11 +107,11 @@ func TestSubmitFastFail(t *testing.T) {
|
||||
// mkDeferredEv 构造快路径事件载荷。
|
||||
func mkDeferredEv(t *testing.T, taskNo, content string, detailID int64, mobile string) []byte {
|
||||
t.Helper()
|
||||
b, err := json.Marshal(SubmitEvent{
|
||||
TaskNo: taskNo, AccountID: 1001, SendType: SendTypeBatch, Deferred: true,
|
||||
TaskMeta: &SubmitTaskMeta{Content: content, Sign: "梦网", MobileCount: 1,
|
||||
FeeTotal: 1, SubmitIP: "protocol", Source: TaskSourceCMPP},
|
||||
Details: []EventDetail{{ID: detailID, Mobile: mobile, Content: content,
|
||||
b, err := json.Marshal(submit.SubmitEvent{
|
||||
TaskNo: taskNo, AccountID: 1001, SendType: submit.SendTypeBatch, Deferred: true,
|
||||
TaskMeta: &submit.SubmitTaskMeta{Content: content, Sign: "梦网", MobileCount: 1,
|
||||
FeeTotal: 1, SubmitIP: "protocol", Source: submit.TaskSourceCMPP},
|
||||
Details: []submit.EventDetail{{ID: detailID, Mobile: mobile, Content: content,
|
||||
Status: 0, Fee: 1}},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -151,7 +152,7 @@ func TestHandleDeferredPass(t *testing.T) {
|
||||
if err := db.Where("task_no = ?", "DF-PASS-1").First(&task).Error; err != nil {
|
||||
t.Fatalf("任务应补建: %v", err)
|
||||
}
|
||||
if task.Source != TaskSourceCMPP || task.MobileCount != 1 || task.Status != taskStDone {
|
||||
if task.Source != submit.TaskSourceCMPP || task.MobileCount != 1 || task.Status != submit.TaskStDone {
|
||||
t.Fatalf("补建任务字段异常: source=%d mobile=%d status=%d",
|
||||
task.Source, task.MobileCount, task.Status)
|
||||
}
|
||||
@@ -215,7 +216,7 @@ func TestHandleDeferredBlocked(t *testing.T) {
|
||||
if err := db.Where("task_no = ?", "DF-BLK-1").First(&task).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if task.Status != taskStDone {
|
||||
if task.Status != submit.TaskStDone {
|
||||
t.Fatalf("全拦任务应终态,got status=%d", task.Status)
|
||||
}
|
||||
if len(dp.calls) != 0 {
|
||||
@@ -0,0 +1,64 @@
|
||||
// helpers_test.go S1-B 拆包:测试库构造自 dispatch/timer_test.go newTimerDB 同体复制
|
||||
// (跨包测试 helper 不可引,本地化;口径一致:sqlite 内存 + task/detail 两表)。
|
||||
package consume
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"go-sms/internal/model/entity"
|
||||
)
|
||||
|
||||
// newTimerDB 消费域测试库。
|
||||
func newTimerDB(t *testing.T) *gorm.DB {
|
||||
t.Helper()
|
||||
db, err := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, m := range []any{&entity.MessageTask{}, &entity.MessageDetail{}} {
|
||||
if err := db.Migrator().CreateTable(m); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
// fakeDispatcher 测试分发器(dispatch.TaskDispatcher 替身;自 dispatch/timer_test.go 同体复制)。
|
||||
type fakeDispatcher struct {
|
||||
calls []int64
|
||||
err error
|
||||
}
|
||||
|
||||
func (f *fakeDispatcher) Dispatch(_ context.Context, task *entity.MessageTask) (int64, int64, error) {
|
||||
if f.err != nil {
|
||||
return 0, 0, f.err
|
||||
}
|
||||
f.calls = append(f.calls, task.ID)
|
||||
return int64(task.MobileCount), 0, nil
|
||||
}
|
||||
|
||||
// getTask 取任务断言用(自 dispatch/timer_test.go 同体复制)。
|
||||
func getTask(t *testing.T, db *gorm.DB, id int64) entity.MessageTask {
|
||||
var task entity.MessageTask
|
||||
if err := db.First(&task, id).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return task
|
||||
}
|
||||
|
||||
// captureSink 事件捕获(自 submit/pipeline_test.go 同体复制;桥接测试本地化)。
|
||||
type captureSink struct {
|
||||
events []*entity.MessageTask
|
||||
details [][]entity.MessageDetail
|
||||
}
|
||||
|
||||
func (c *captureSink) EmitSubmit(_ context.Context, t *entity.MessageTask,
|
||||
d []entity.MessageDetail) error {
|
||||
c.events = append(c.events, t)
|
||||
c.details = append(c.details, d)
|
||||
return nil
|
||||
}
|
||||
@@ -2,10 +2,11 @@
|
||||
// 通道+内容 相同的明细聚合为批:满 maxBatch(1000)立即 flush,或窗口(5s)到期统一
|
||||
// flush——同批一次批量提交(CMPP 单包 ≤100 号码,由通道层切包),显著降低
|
||||
// 提交调用次数(验收口径:较逐号提交减少 ≥80%)。
|
||||
package send
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go-sms/internal/service/send/submit"
|
||||
"strconv"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -180,11 +181,11 @@ func (a *SubmitAggregator) flushGroup(g *aggrGroup) {
|
||||
}
|
||||
a.singleTotal.Add(1)
|
||||
}
|
||||
a.markIDs(ctx, okIDs, detailStSubmitted, g.channelID, "")
|
||||
a.markIDs(ctx, failIDs, detailStFailed, g.channelID, errText(err))
|
||||
a.markIDs(ctx, okIDs, submit.DetailStSubmitted, g.channelID, "")
|
||||
a.markIDs(ctx, failIDs, submit.DetailStFailed, g.channelID, errText(err))
|
||||
return
|
||||
}
|
||||
a.markIDs(ctx, ids, detailStSubmitted, g.channelID, "")
|
||||
a.markIDs(ctx, ids, submit.DetailStSubmitted, g.channelID, "")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -202,8 +203,8 @@ func (a *SubmitAggregator) flushGroup(g *aggrGroup) {
|
||||
}
|
||||
a.singleTotal.Add(1)
|
||||
}
|
||||
a.markIDs(ctx, okIDs, detailStSubmitted, g.channelID, "")
|
||||
a.markIDs(ctx, failIDs, detailStFailed, g.channelID, lastErr)
|
||||
a.markIDs(ctx, okIDs, submit.DetailStSubmitted, g.channelID, "")
|
||||
a.markIDs(ctx, failIDs, submit.DetailStFailed, g.channelID, lastErr)
|
||||
}
|
||||
|
||||
// markIDs 批量终态回写(mark 未绑定时忽略——纯内存测试场景)。
|
||||
+3
-2
@@ -1,11 +1,12 @@
|
||||
// aggregator_test.go Day 47:合包聚合器单测——双阈值触发(1000 条即时/窗口到期)、
|
||||
// 调用次数削减(验收口径 ≥80%)、批量失败逐号回退、分发器聚合接线。
|
||||
package send
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go-sms/internal/service/send/submit"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
@@ -195,7 +196,7 @@ func TestDispatcher_WithAggregator(t *testing.T) {
|
||||
t.Fatalf("批量调用=%d(任务级即时冲洗)", n)
|
||||
}
|
||||
var cnt int64
|
||||
db.Model(&entity.MessageDetail{}).Where("channel_id = ? AND status = ?", 7, detailStSubmitted).Count(&cnt)
|
||||
db.Model(&entity.MessageDetail{}).Where("channel_id = ? AND status = ?", 7, submit.DetailStSubmitted).Count(&cnt)
|
||||
if cnt != 20 {
|
||||
t.Fatalf("明细终态落库=%d/20", cnt)
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
// L3 lag>500 万 → 暂停低优先级投放(消费组 Pause;恢复即 Resume)。
|
||||
//
|
||||
// 水位键由消费者进程写入(30s TTL,采样周期 10s),网关进程只读——跨进程解耦。
|
||||
package send
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// backpressure_test.go Day 48:三级水位单测——阈值判定/边缘动作(暂停恢复)/
|
||||
// 水位键写入(miniredis)/ReadBPLevel 网关侧读取。
|
||||
package send
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
// 攒批(默认 500 条/批)× N 并发 worker 异步 UPDATE ... WHERE id IN(...),
|
||||
// 保证 MySQL 批量写入不阻塞 Kafka 消费(lag 不因落库增长)。
|
||||
// Add 非阻塞:通道满/已关闭返回 false,调用方直写兜底(可用性优先)。
|
||||
package send
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"sync"
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// batchwriter_test.go Day 48:明细终态批量落库 writer 单测——分片落库/截断/
|
||||
// Close 冲刷/空批。
|
||||
package send
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -4,7 +4,7 @@
|
||||
// - p50>50ms 持续 30s 自动降速 10%(单向,Reset 手动恢复);
|
||||
// - PaceBudget:群发匀速投放预算——每轮 min(剩余, Σ通道speed − 在途余量),
|
||||
// 防瞬时打满下游队列(技术方案 10.4.1)。
|
||||
package send
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,5 +1,5 @@
|
||||
// pacer_test.go Day 48:下发调度三件套单测——令牌桶限速/在途窗口/自动降速/匀速预算。
|
||||
package send
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -2,7 +2,7 @@
|
||||
// (msg_id+mobile 唯一),回执消费者按段置态聚合判 detail 终态(A-5.2)。
|
||||
// 写入失败仅日志不上抛:seg 缺失=该段回执到达时无配对(挂起日志),
|
||||
// 资损安全方向与 UNKNOWN 一致(宁可挂起不可错判)。
|
||||
package send
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,5 +1,5 @@
|
||||
// seg_test.go Day 56:段级配对登记构造单测——单号 N 段/合包包×片展开。
|
||||
package send
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"go-sms/internal/service/channel/pool"
|
||||
@@ -10,11 +10,12 @@
|
||||
// ③ Redis 不可用时 q=nil,纯 DB 扫描降级(行为等价,ZSet 仅省全表轮询);
|
||||
// ④ 到点分发经 TaskDispatcher(router 选路→CMPP 链路提交);
|
||||
// 逐号独立成败,任务终态置 2 完成并回填计数;系统性错误回滚 status=1→0 下轮重试。
|
||||
package send
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"go-sms/internal/service/send/submit"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -29,15 +30,6 @@ import (
|
||||
// ErrDetailsNotReady 明细尚未落库(Day52 R2:事件明细在途,回滚认领留待重扫)。
|
||||
var ErrDetailsNotReady = errors.New("明细尚未落库")
|
||||
|
||||
// 审核态/任务态稳定契约值(与 audit 包常量一致;避免 send→audit 本体依赖)。
|
||||
const (
|
||||
auditReadyExempt = 3 // 免审(可发)
|
||||
taskStSending = 1
|
||||
taskStDone = 2
|
||||
detailStSubmitted = 1 // 明细:已提交
|
||||
detailStFailed = 3 // 明细:失败
|
||||
)
|
||||
|
||||
// TaskQueue 定时任务唤醒索引(Redis ZSet 实现;测试可替身)。
|
||||
type TaskQueue interface {
|
||||
Enqueue(ctx context.Context, taskID int64, at time.Time) error
|
||||
@@ -177,7 +169,7 @@ func (d *ChannelDispatcher) Dispatch(ctx context.Context, task *entity.MessageTa
|
||||
AccountID: task.AccountID, Content: det.Content, Signature: task.Sign,
|
||||
})
|
||||
if perr != nil {
|
||||
d.markDetail(ctx, det.ID, detailStFailed, chID, "NO_ROUTE:"+perr.Error(), now)
|
||||
d.markDetail(ctx, det.ID, submit.DetailStFailed, chID, "NO_ROUTE:"+perr.Error(), now)
|
||||
failed++
|
||||
continue
|
||||
}
|
||||
@@ -191,7 +183,7 @@ func (d *ChannelDispatcher) Dispatch(ctx context.Context, task *entity.MessageTa
|
||||
// Day48④:直发路径限速(令牌桶+在途窗口;未启用直通)+延迟采样降速判定。
|
||||
if d.pacer != nil {
|
||||
if aerr := d.pacer.Acquire(ctx, chID, 1); aerr != nil {
|
||||
d.markDetail(ctx, det.ID, detailStFailed, chID, aerr.Error(), now)
|
||||
d.markDetail(ctx, det.ID, submit.DetailStFailed, chID, aerr.Error(), now)
|
||||
failed++
|
||||
continue
|
||||
}
|
||||
@@ -203,13 +195,13 @@ func (d *ChannelDispatcher) Dispatch(ctx context.Context, task *entity.MessageTa
|
||||
d.pacer.Release(chID, 1)
|
||||
}
|
||||
if serr != nil {
|
||||
d.markDetail(ctx, det.ID, detailStFailed, chID, serr.Error(), now)
|
||||
d.markDetail(ctx, det.ID, submit.DetailStFailed, chID, serr.Error(), now)
|
||||
failed++
|
||||
continue
|
||||
}
|
||||
// Day 56:段级配对登记(单号 1~9 段,每段独立 msg_id)。
|
||||
writeSegRows(ctx, d.db, segRowsFor(chID, det.ID, det.Mobile, msgIDs))
|
||||
d.markDetail(ctx, det.ID, detailStSubmitted, chID, "", now)
|
||||
d.markDetail(ctx, det.ID, submit.DetailStSubmitted, chID, "", now)
|
||||
sent++
|
||||
}
|
||||
if d.agg != nil {
|
||||
@@ -266,7 +258,7 @@ func (s *TimerScheduler) ScanOnce(ctx context.Context) (enq, claimed, done int,
|
||||
if s.q != nil {
|
||||
var pend []entity.MessageTask
|
||||
if err = s.db.WithContext(ctx).
|
||||
Where("send_type = ? AND status = 0 AND audit_status IN (1, 3)", SendTypeTimer).
|
||||
Where("send_type = ? AND status = 0 AND audit_status IN (1, 3)", submit.SendTypeTimer).
|
||||
Order("schedule_at ASC").Limit(200).Find(&pend).Error; err != nil {
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
@@ -286,7 +278,7 @@ func (s *TimerScheduler) ScanOnce(ctx context.Context) (enq, claimed, done int,
|
||||
var invalid []entity.MessageTask
|
||||
if err = s.db.WithContext(ctx).
|
||||
Where("id IN ? AND NOT (send_type = ? AND status = 0 AND audit_status IN (1, 3))",
|
||||
all, SendTypeTimer).Find(&invalid).Error; err == nil {
|
||||
all, submit.SendTypeTimer).Find(&invalid).Error; err == nil {
|
||||
for _, t := range invalid {
|
||||
_ = s.q.Remove(ctx, t.ID)
|
||||
}
|
||||
@@ -305,7 +297,7 @@ func (s *TimerScheduler) ScanOnce(ctx context.Context) (enq, claimed, done int,
|
||||
var rows []entity.MessageTask
|
||||
if err = s.db.WithContext(ctx).
|
||||
Where("send_type = ? AND status = 0 AND audit_status IN (1, 3) AND schedule_at <= ?",
|
||||
SendTypeTimer, now).
|
||||
submit.SendTypeTimer, now).
|
||||
Order("schedule_at ASC").Limit(s.batch).Find(&rows).Error; err != nil {
|
||||
return enq, 0, 0, err
|
||||
}
|
||||
@@ -337,8 +329,8 @@ func (s *TimerScheduler) ScanOnce(ctx context.Context) (enq, claimed, done int,
|
||||
func (s *TimerScheduler) claim(ctx context.Context, id int64, now time.Time) (bool, error) {
|
||||
res := s.db.WithContext(ctx).Model(&entity.MessageTask{}).
|
||||
Where("id = ? AND send_type = ? AND status = 0 AND audit_status IN (1, 3) AND schedule_at <= ?",
|
||||
id, SendTypeTimer, now).
|
||||
Update("status", taskStSending)
|
||||
id, submit.SendTypeTimer, now).
|
||||
Update("status", submit.TaskStSending)
|
||||
return res.RowsAffected == 1, res.Error
|
||||
}
|
||||
|
||||
@@ -353,7 +345,7 @@ func (s *TimerScheduler) reconcile(ctx context.Context, id int64) {
|
||||
_ = s.q.Remove(ctx, id) // 已删除任务:清索引
|
||||
return
|
||||
}
|
||||
if t.Status == 0 && (t.AuditStatus == 1 || t.AuditStatus == auditReadyExempt) &&
|
||||
if t.Status == 0 && (t.AuditStatus == 1 || t.AuditStatus == submit.AuditReadyExempt) &&
|
||||
t.ScheduleAt != nil && t.ScheduleAt.After(time.Now()) {
|
||||
_ = s.q.Enqueue(ctx, id, *t.ScheduleAt) // 改期:重排新时刻
|
||||
return
|
||||
@@ -371,14 +363,14 @@ func (s *TimerScheduler) dispatch(ctx context.Context, id int64) bool {
|
||||
sent, failed, derr := s.dp.Dispatch(ctx, &task)
|
||||
if derr != nil {
|
||||
_ = s.db.WithContext(ctx).Model(&entity.MessageTask{}).
|
||||
Where("id = ? AND status = ?", id, taskStSending).
|
||||
Where("id = ? AND status = ?", id, submit.TaskStSending).
|
||||
Update("status", 0).Error
|
||||
return false
|
||||
}
|
||||
res := s.db.WithContext(ctx).Model(&entity.MessageTask{}).
|
||||
Where("id = ? AND status = ?", id, taskStSending).
|
||||
Where("id = ? AND status = ?", id, submit.TaskStSending).
|
||||
Updates(map[string]any{
|
||||
"status": taskStDone, "success_count": sent, "fail_count": failed,
|
||||
"status": submit.TaskStDone, "success_count": sent, "fail_count": failed,
|
||||
"finished_at": time.Now(),
|
||||
})
|
||||
if res.Error != nil || res.RowsAffected == 0 {
|
||||
@@ -1,9 +1,10 @@
|
||||
// timer_test.go Day 45:定时调度单测——miniredis 真 ZSet 队列+sqlite:
|
||||
// 到点认领分发终态/幂等二轮/未来不入/改期重排/取消清理/纯 DB 降级/分发错误回滚重试。
|
||||
package send
|
||||
package dispatch
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go-sms/internal/service/send/submit"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -63,7 +64,7 @@ func mkTimerTask(t *testing.T, db *gorm.DB, at time.Time, audit int8) *entity.Me
|
||||
ttSeq++
|
||||
task := &entity.MessageTask{
|
||||
TaskNo: "TT" + time.Now().Format("150405.000000000") + "_",
|
||||
AccountID: 1001, SendType: SendTypeTimer, Content: "【店】测试", Sign: "店",
|
||||
AccountID: 1001, SendType: submit.SendTypeTimer, Content: "【店】测试", Sign: "店",
|
||||
MobileCount: 2, AuditStatus: audit, Status: 0, ScheduleAt: &at,
|
||||
}
|
||||
task.TaskNo += time.Duration(ttSeq).String()
|
||||
@@ -0,0 +1,79 @@
|
||||
// Package send 发送域门面(S1-B P2 拆包,2026-11-13):
|
||||
// 实现按 设计规范 §一 拆为三子包——submit(受理:SubmitService/Pipeline/校验/文件导入/
|
||||
// 退款,事件契约与状态契约族)、consume(消费:handleDeferred 补全/补偿扫描)、
|
||||
// dispatch(下发:TimerScheduler+ChannelDispatcher/聚合/限速/背压/批量落库/段登记)。
|
||||
// 本包保留类型/函数/常量别名门面,外部调用方(api/openapi/access/report/cmd)零改动;
|
||||
// 新代码建议直接 import 子包。依赖方向:consume→{submit,dispatch},dispatch→submit,单向无环。
|
||||
package send
|
||||
|
||||
import (
|
||||
"go-sms/internal/service/send/consume"
|
||||
"go-sms/internal/service/send/dispatch"
|
||||
"go-sms/internal/service/send/submit"
|
||||
)
|
||||
|
||||
// ---- submit(受理) ----
|
||||
|
||||
type (
|
||||
SubmitService = submit.SubmitService
|
||||
SubmitReq = submit.SubmitReq
|
||||
SubmitOption = submit.SubmitOption
|
||||
PersonalItem = submit.PersonalItem
|
||||
FileImportService = submit.FileImportService
|
||||
ProducerSink = submit.ProducerSink
|
||||
)
|
||||
|
||||
const (
|
||||
TaskSourceCMPP = submit.TaskSourceCMPP
|
||||
TaskSourceSMPP = submit.TaskSourceSMPP
|
||||
TaskSourceAPI = submit.TaskSourceAPI
|
||||
TaskSourceWeb = submit.TaskSourceWeb
|
||||
SendTypeTimer = submit.SendTypeTimer
|
||||
SendTypeBatch = submit.SendTypeBatch
|
||||
MaxPersonalItems = submit.MaxPersonalItems
|
||||
MaxMobiles = submit.MaxMobiles
|
||||
ContentEncodingUCS2 = submit.ContentEncodingUCS2
|
||||
ContentEncodingDefault = submit.ContentEncodingDefault
|
||||
)
|
||||
|
||||
var (
|
||||
NewSubmitService = submit.NewSubmitService
|
||||
WithEventSink = submit.WithEventSink
|
||||
WithBalanceStore = submit.WithBalanceStore
|
||||
WithInterceptorChain = submit.WithInterceptorChain
|
||||
NormalizeTaskSource = submit.NormalizeTaskSource
|
||||
NewFileImportService = submit.NewFileImportService
|
||||
)
|
||||
|
||||
// ---- consume(消费) ----
|
||||
|
||||
type ReclaimScanner = consume.ReclaimScanner
|
||||
|
||||
var (
|
||||
NewSubmitConsumer = consume.NewSubmitConsumer
|
||||
NewReclaimScanner = consume.NewReclaimScanner
|
||||
)
|
||||
|
||||
// ---- dispatch(下发) ----
|
||||
|
||||
type TaskQueue = dispatch.TaskQueue
|
||||
|
||||
const (
|
||||
DefaultAggrWindow = dispatch.DefaultAggrWindow
|
||||
DefaultAggrMaxBatch = dispatch.DefaultAggrMaxBatch
|
||||
DefaultWriterWorker = dispatch.DefaultWriterWorker
|
||||
DefaultWriterBatch = dispatch.DefaultWriterBatch
|
||||
DefaultChannelSpeed = dispatch.DefaultChannelSpeed
|
||||
)
|
||||
|
||||
var (
|
||||
QueueKey = dispatch.QueueKey
|
||||
NewRedisZSetQueue = dispatch.NewRedisZSetQueue
|
||||
NewSubmitAggregator = dispatch.NewSubmitAggregator
|
||||
NewChannelDispatcher = dispatch.NewChannelDispatcher
|
||||
NewTimerScheduler = dispatch.NewTimerScheduler
|
||||
NewDetailWriter = dispatch.NewDetailWriter
|
||||
NewChannelPacer = dispatch.NewChannelPacer
|
||||
NewBackpressure = dispatch.NewBackpressure
|
||||
NewRedisBPStore = dispatch.NewRedisBPStore
|
||||
)
|
||||
@@ -1,5 +1,5 @@
|
||||
// P0-1 诊断(临时,Day63 复压定位):快路径分段耗时打点。
|
||||
package send
|
||||
package submit
|
||||
|
||||
import (
|
||||
"time"
|
||||
@@ -0,0 +1,62 @@
|
||||
// event.go S1-B 拆包:submit 事件契约(原 consumer.go 顶部三类型;生产者持有契约,
|
||||
// consume 消费侧经 import submit 引用——依赖方向 consume→submit 单向)。
|
||||
// 状态契约常量族(原 dispatch/timer.go;跨三子包共用,迁契约所有者=submit 并导出)。
|
||||
package submit
|
||||
|
||||
// 审核态/任务态稳定契约值(与 audit 包常量一致;避免 send→audit 本体依赖)。
|
||||
const (
|
||||
AuditReadyExempt = 3 // 免审(可发)
|
||||
TaskStSending = 1
|
||||
TaskStDone = 2
|
||||
DetailStSubmitted = 1 // 明细:已提交
|
||||
DetailStFailed = 3 // 明细:失败
|
||||
)
|
||||
|
||||
// SubmitEvent sms-submit 事件载荷(Day46 openapi 五字段向后兼容+Day48 扩展+Day52 R2 明细全量)。
|
||||
type SubmitEvent struct {
|
||||
TaskID int64 `json:"task_id"`
|
||||
TaskNo string `json:"task_no"`
|
||||
AccountID int64 `json:"account_id"`
|
||||
SendType int8 `json:"send_type"`
|
||||
PassCount int `json:"pass_count"` // 过拦截条数(0=全拦,消费者跳过;Day52 起由 details 推导)
|
||||
Source string `json:"source"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
Business string `json:"business,omitempty"` // Day 49:sms/video(biz_type 路由;空=sms 兼容 Day48 旧载荷)
|
||||
// Day52 R2:明细全量(入口预生成雪花 ID+拦截终态;消费侧批量落库,入口事务零明细写)。
|
||||
// 空=Day48 旧格式/兜底扫描场景,消费侧不落(明细已由降级路径或旧版本落库)。
|
||||
Details []EventDetail `json:"details,omitempty"`
|
||||
// P0-1(Day 63)接入异步化:Deferred=true 表示受理侧走 SubmitFast 快路径
|
||||
// (Validate+预扣+DetailID 预生成+投递,零 DB 写),task 落库/拦截判定/退费/
|
||||
// 审核分流全部由消费侧补全(handleDeferred);TaskID=0(自增主键消费侧生成)。
|
||||
Deferred bool `json:"deferred,omitempty"`
|
||||
// TaskMeta Deferred 专用:任务行补建字段(与 entity.MessageTask 对齐;
|
||||
// 旧事件零携带,消费侧按非 Deferred 老路径处理)。
|
||||
TaskMeta *SubmitTaskMeta `json:"task_meta,omitempty"`
|
||||
}
|
||||
|
||||
// SubmitTaskMeta 快路径任务补建载荷(受理侧未落库,消费侧 INSERT 重建)。
|
||||
type SubmitTaskMeta struct {
|
||||
Content string `json:"content"`
|
||||
Sign string `json:"sign"`
|
||||
MobileCount int `json:"mobile_count"`
|
||||
FeeTotal float64 `json:"fee_total"`
|
||||
SubmitIP string `json:"submit_ip"`
|
||||
CallData string `json:"call_data"`
|
||||
Source int8 `json:"source"` // 任务来源 int8(WEB=4/CMPP=2/SMPP=3/API=1)
|
||||
ScheduleAt string `json:"schedule_at,omitempty"` // RFC3339,空=非定时
|
||||
}
|
||||
|
||||
// EventDetail 明细行载荷(task_id/account_id 公共字段在事件级;字段与 entity.MessageDetail 对齐)。
|
||||
type EventDetail struct {
|
||||
ID int64 `json:"id"` // 雪花主键(入口预生成,回执配对键)
|
||||
Mobile string `json:"mobile"`
|
||||
Content string `json:"content"`
|
||||
Status int8 `json:"status"` // 0=存活 5=拦截终态(受理期已退费)
|
||||
Fee float64 `json:"fee"` // 计费条数
|
||||
ErrorCode string `json:"error_code,omitempty"`
|
||||
ExtCode string `json:"ext_code,omitempty"`
|
||||
CallData string `json:"call_data,omitempty"`
|
||||
// Day66:明细单表化冗余(空=旧载荷,persistDetailsDB 兜底 ev.Business/'sms')。
|
||||
Business string `json:"business,omitempty"`
|
||||
Source int8 `json:"source,omitempty"` // 0=旧载荷→兜底 API
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// fileimport.go Day 44:号码文件导入服务(文件入口)——multipart 上传→解析(TXT/CSV/XLSX)
|
||||
// →归一校验去重→原始文件落 MinIO→返回计数/预览/对象键。
|
||||
// 与 SubmitService 解耦:导入只做「号码准备」,提交仍走 POST /send/submit(文件类型 send_type=4)。
|
||||
package send
|
||||
package submit
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
// fileimport_test.go Day 44:导入服务——去重/非法/表头启发/超限/对象键(依赖倒置 memStore)。
|
||||
package send
|
||||
package submit
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -7,7 +7,7 @@
|
||||
//
|
||||
// 路由/下发不在受理期(同步链路 ≤5ms 禁令,技术方案 10.4):由 submit 消费者
|
||||
// (consumer.go)认领后经 ChannelDispatcher 路由→pacer 限速→聚合/直发链路完成。
|
||||
package send
|
||||
package submit
|
||||
|
||||
import (
|
||||
"context"
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
// pipeline_test.go Day 48:全流程状态机单测——预扣/拦截退费/全拦终态/审核拒绝退费/
|
||||
// 落库失败对冲/事件投递口径(验收:失败各环节回退余额)。
|
||||
package send
|
||||
package submit
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -4,7 +4,7 @@
|
||||
// Day 54 R1:预扣/退款统一走 balance.Store(mysql 行锁|redis Lua+异步流水,
|
||||
// 评审 docs/review/r1-balance.md);本文件保留 MySQL 原路径实现,
|
||||
// 由 balance.MySQLStore 与回退路径复用。
|
||||
package send
|
||||
package submit
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,4 +1,4 @@
|
||||
package send
|
||||
package submit
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -181,9 +181,9 @@ func (s *SubmitService) Submit(ctx context.Context, req *SubmitReq, tpl *entity.
|
||||
_ = s.db.WithContext(ctx).Model(&entity.MessageTask{}).
|
||||
Where("id = ? AND status = ?", task.ID, 0).
|
||||
Updates(map[string]any{
|
||||
"status": taskStDone, "fail_count": len(mobiles), "finished_at": time.Now(),
|
||||
"status": TaskStDone, "fail_count": len(mobiles), "finished_at": time.Now(),
|
||||
}).Error
|
||||
task.Status = taskStDone
|
||||
task.Status = TaskStDone
|
||||
task.FailCount = len(mobiles)
|
||||
return &SubmitResult{Task: &task, Estimate: est}, nil
|
||||
}
|
||||
@@ -470,9 +470,9 @@ func (s *SubmitService) SubmitPersonal(ctx context.Context, accountID int64,
|
||||
_ = s.db.WithContext(ctx).Model(&entity.MessageTask{}).
|
||||
Where("id = ? AND status = ?", task.ID, 0).
|
||||
Updates(map[string]any{
|
||||
"status": taskStDone, "fail_count": len(merged), "finished_at": time.Now(),
|
||||
"status": TaskStDone, "fail_count": len(merged), "finished_at": time.Now(),
|
||||
}).Error
|
||||
task.Status = taskStDone
|
||||
task.Status = TaskStDone
|
||||
task.FailCount = len(merged)
|
||||
return &SubmitResult{Task: &task}, nil
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
// submit_source_test.go Day 60(D24-25):受理来源打标——SubmitReq.Source/
|
||||
// SubmitPersonal source 归一(0/非法→API=1;入口显式 2 CMPP/3 SMPP/4 WEB),
|
||||
// message_task.source 落库供下行明细 v2 筛选。
|
||||
package send
|
||||
package submit
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,6 +1,6 @@
|
||||
// submit_test.go Day 43 修复循环:最小提交链单测——立即/定时受理+明细雪花落库/
|
||||
// 三模式分流接线/余额只读校验/任务号幂等。
|
||||
package send
|
||||
package submit
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -1,6 +1,6 @@
|
||||
// Package send Day 41(阶段 4 起步):发送域——Submit DTO+发送校验器+计费预估。
|
||||
// Day 44 群发/个性/文件服务与 Day 46 HTTP API 提交接口复用本包校验。
|
||||
package send
|
||||
package submit
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
// validator_test.go Day 41:发送校验器——长度/号码/变量/签名拒绝路径+预估条数。
|
||||
package send
|
||||
package submit
|
||||
|
||||
import (
|
||||
"strings"
|
||||
@@ -1,15 +1,15 @@
|
||||
# 当前工作上下文(最近更新:2026-11-12)
|
||||
|
||||
## 当前状态快照(2026-11-13 晚,S1-B D1+B 层全域 P1 完成日)
|
||||
## 当前状态快照(2026-11-13 夜,**S1 泳道收官**)
|
||||
|
||||
- **仓库**:main 至 `704f6f0`(今日 S1-B 14 提交:5986680→704f6f0);module 保持 `go-sms`;每日 03:30 bundle 备份照常。
|
||||
- **中间件**:9/9 容器 healthy(mysql 10G/2000/10000/redo1G·SSD 基线生效、kafka compose 化 KRaft、redis/etcd/CH/prom/am/jaeger、**rustfs 1.0.5**);~~minio 遗留~~**已销账(2026-11-13 晚:MinIO 收费化 → RustFS 替换,compose 服务换血+集成测试 TestStorage_RustFS_S3Compat 门禁,minio-go SDK 零改动实测兼容;D1 镜像拉取遗留随之消解)**。
|
||||
- **init 链**:4 topic×3 分区 ✓;**迁移链 v1~v19 空库独建+超管**(admin/4b5fc0333cd402c5,已交用户);**教训:init_schema.sql 快照与 gormigrate 双跑会 FK 冲突(Error 3780)——新环境只走迁移链,快照降级参考资产**。
|
||||
- **B 层搬运**:P1 全域 12 域+双入口落位(两阶段等价法);channel P2 拆 pool 子包完成(Deps 断环六适配);**send P2 拆三子包=下一工作项**;dayNN 九文件改名/account·template 文案校准待收口。
|
||||
- **质量门**:build/vet/lint(v2.1.6 首跑 27→0)/全仓 -race 36 包绿/集成六件绿/router MySQL 硬断言 p99=9.4ms·1620s;sqlite 口径 TestPick1000QPS 222/s 定性=无中间件环境差异非回归(测试自动探测 :13306)。
|
||||
- **运行中**:gateway :8081(pid 232639)冒烟驻留;**24h 稳定性门槛 17:55 起计**(dmesg 零新增+进程零重启,首份快照 logs/1m-baseline.txt)。
|
||||
- 归档仓(只读):/data/poc-archive/repos/go-sms.git(poc-final=5e09a4cc)。**Gitea 已闭环**:origin=`ssh://git@192.168.5.27:24401/Tory/go-sms-V2.git`(2026-11-13 push main=f1af4fb 20 提交 ✓;运营探讨入口=web 渲染 memory-bank/docs/Go-sms-重建计划.md)。
|
||||
- **本会话运维教训**:①`pkill/pgrep -f` 自匹配四连(铁律:模式用 `[x]` 括号技巧或两步 PID 文件法);②docker 拉取大镜像单窗必须 >镜像体积/带宽(CH 950MB@1MB/s 需 1800s 窗,300s 窗永远截断大层);③du 无 sudo 静默失败会误诊"零字节停滞"。
|
||||
- **仓库**:main 已推 Gitea(origin=192.168.5.27:24401/Tory/go-sms-V2);S1 全程共 30 提交(2a6a66f→收官对账);每日 bundle+push 双轨。
|
||||
- **S1 出口全绿**:B 层 12 域+结构改造三件(send 拆包 facade/channel 拆 pool/router 空壳消除)+dayNN 清零+lint 0+**全仓 -race 38 包 RC=0**+集成七件+gateway 驻留冒烟;迁移链 v1~v19 落地。
|
||||
- **send 三子包**(0550f2a):submit(受理+事件/状态契约族)/consume/dispatch;facade.go 40 符号别名门面,调用方零改动;依赖 consume→{submit,dispatch}、dispatch→submit 单向。
|
||||
- **中间件**:9/9 healthy(MySQL 10G SSD 基线/kafka compose 化/rustfs);gateway :8081 驻留。
|
||||
- **在途**:24h 稳定性门槛(11-13 17:55 起,至今 dmesg 0/重启 0)→ **11-14 17:55 期满核验回填 s1-b-closeout.md**(S5 压测基线前置)。
|
||||
- **下一步=S2 结算域**(5 工作日,D 层新做):开工前置=研读《需求分析》结算章节+表设计评审先行(整域 0% 起点);随后 S3 前端(views 31 页+FE-6+node 工具链)。
|
||||
- 归档仓(只读):/data/poc-archive/repos/go-sms.git(poc-final=5e09a4cc)。
|
||||
- **本会话运维教训**:①`pkill/pgrep -f` 自匹配(铁律:`[x]` 括号技巧);②大镜像单窗>体积÷带宽;③du 无 sudo 静默失败误诊;④sed 换行/sed 误伤方法名(重构期优先编辑器工具);⑤Go 工具忽略 `_` 前缀文件;⑥集成测试需 `sg docker` 包裹(docker 组未重登)。
|
||||
|
||||
## 重建启动(2026-11-12 裁决 / 盘点 / 迁移方案)
|
||||
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
| S1② git init+A 层搬运 | 2a6a66f 地基 → e47610f A 层 273 文件 +33973(源=poc-final 5e09a4cc);build/vet/-race **23 包全绿 65s** | ✅ 2026-11-13 |
|
||||
| S1-B D1 中间件+基线 | compose SSD 参数生效/Kafka compose 化/迁移链 v1~v19 落地/集成六件绿/首份快照/24h 门槛起计 | ✅ 2026-11-13(minio 镜像遗留) |
|
||||
| S1-B B 层搬运 P1 | 12 域+双入口全落位(两阶段等价法);channel P2 拆 pool 完成;lint 27→0;全仓 -race 36 包绿 | ✅ 2026-11-13 |
|
||||
| S1-B 收尾项 | send P2 拆三子包/dayNN 九文件语义改名/account·template 文案校准/minio 镜像/gofmt 存量 20 文件待议 | ⬜ 下工作日 |
|
||||
| S1-B 收尾项 | send P2 拆三子包(0550f2a,facade 门面)/dayNN 19 文件改名/storage 归一/文案校准/gofmt 清零 | ✅ 2026-11-13 夜(**S1 泳道收官**) |
|
||||
| 观察项 | 24h 稳定性门槛期满核验(11-14 17:55)→ s1-b-closeout.md 回填 | ⏳ 在途 |
|
||||
| S2~S5 | 结算域/前端收尾/C1C2+冷热/基线与灰度 | ⬜ 见《Go-sms-重建计划.md》 |
|
||||
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func TestStorage_RustFS_S3Compat(t *testing.T) {
|
||||
s, err := storage.NewMinIO(context.Background(), "127.0.0.1:19010", "go-sms", "go-sms123456", "gosms-it", false)
|
||||
s, err := storage.NewS3(context.Background(), "127.0.0.1:19010", "go-sms", "go-sms123456", "gosms-it", false)
|
||||
if err != nil {
|
||||
t.Skipf("对象存储(19010)不可达,跳过(make up): %v", err)
|
||||
}
|
||||
@@ -31,7 +31,7 @@ func TestStorage_RustFS_S3Compat(t *testing.T) {
|
||||
t.Fatalf("Put 幂等覆盖失败: %v", err)
|
||||
}
|
||||
// 二次构造(桶已存在分支)
|
||||
if _, err := storage.NewMinIO(ctx, "127.0.0.1:19010", "go-sms", "go-sms123456", "gosms-it", false); err != nil {
|
||||
if _, err := storage.NewS3(ctx, "127.0.0.1:19010", "go-sms", "go-sms123456", "gosms-it", false); err != nil {
|
||||
t.Fatalf("桶已存在时应幂等成功: %v", err)
|
||||
}
|
||||
t.Log("RustFS S3 兼容面通过: MakeBucket 幂等/Put/覆盖写")
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// gen-dict Day 41(清债②):openapi.yaml x-isc-dict → web/src/api/dict.ts 前端字典 codegen。
|
||||
// 契约源=api/openapi.yaml;与后端 internal/pkg/errors/codes.go 由 openapi_sync_test 双向锁定。
|
||||
// 用法:go run ./tools/gen-dict 生成(默认写 web/src/api/dict.ts)
|
||||
// go run ./tools/gen-dict -check 仅校验,不一致 exit 1(CI/门禁用)
|
||||
//
|
||||
// go run ./tools/gen-dict -check 仅校验,不一致 exit 1(CI/门禁用)
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
Reference in New Issue
Block a user