fix: 修复佣金计算任务载荷二次序列化导致 base64 编码错误
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m11s

问题:EnqueueTask 内部调用 sonic.Marshal,传入 []byte 时会将字节数组
base64 编码为 JSON 字符串,Handler 反序列化时类型不匹配(CommissionCalculationPayload vs string)

根因:order/service.go 的 enqueueCommissionCalculation 预先 Marshal 得到 []byte
后传给 EnqueueTask,导致载荷被二次序列化

修复:直接传入 map,由 EnqueueTask 统一序列化一次

规范同步:
- pkg/queue/client.go 函数注释明确禁止传 []byte
- AGENTS.md 新增「异步任务载荷规范」防止重现
This commit is contained in:
2026-03-31 18:48:17 +08:00
parent 31e147495c
commit 619f029a5a
3 changed files with 37 additions and 15 deletions

View File

@@ -35,8 +35,10 @@ func NewClient(redisClient *redis.Client, logger *zap.Logger) *Client {
}
// EnqueueTask 提交任务到队列
// payload 必须传入 struct 或 map禁止传入 []byte。
// 传入 []byte 会导致 sonic.Marshal 将其 base64 编码handler 解析时类型不匹配。
func (c *Client) EnqueueTask(ctx context.Context, taskType string, payload interface{}, opts ...asynq.Option) error {
// 序列化载荷
// 内部统一序列化,调用方无需预先 Marshal
payloadBytes, err := sonic.Marshal(payload)
if err != nil {
c.logger.Error("任务载荷序列化失败",