阶段六:收口Automation事件与规则边界
This commit is contained in:
1 parent
176ecb7b59
commit
885a5760de
6 files changed
+1355
-1241
No files matched your search
+1138
-1132
File diff suppressed because it is too large.
Load diff
@@ -165,7 +165,8 @@ app shell / routes
|
||||
- 已完成阶段 6 第二个 PR 切片“Engine WebSocket 连接循环边界”:`registerConnection` 在凭证锁内统一快照复核与 WebSocket 注册,`runConnectionSession` 统一心跳、接收、Token 轮换 goroutine 的创建/取消/等待;`Account` 继续负责凭证错误、风控和重连结果解释;新增会话收束测试,未改变冻结风控行为;全量测试、Engine race、Server race、vet、lint、注释和 diff 门禁通过并合并为一个可回滚提交;
|
||||
- 已完成阶段 6 第三个 PR 切片“Engine WebSocket 记录与消息分发边界”:将 WS 记录 worker、消息去重、防抖和并发信号量分别收口到独立组件;`Account` 保留兼容 facade,系统事件背压、聊天洪峰限流、消息顺序、自动化事件优先级和 Stop 等待语义保持不变;全量 Go 测试、Engine/Server race、vet、lint、注释和前端构建门禁通过并合并为一个可回滚提交;
|
||||
- 已完成阶段 6 第四个 PR 切片“Engine 凭证状态与 Token 生命周期边界”:将 Cookie 快照、Token 缓存、刷新锁、设备指纹和刷新诊断状态收口到独立 `credentialState`;运行状态锁改为显式 `runtimeMu`,避免匿名组件锁冲突;保留风控恢复、刷新锁、Cookie/Token 绑定和 WebSocket 注册前快照复核语义;Engine 全量测试、Engine/Server race、vet、lint、注释和前端构建门禁通过并合并为一个可回滚提交;
|
||||
- 阶段 6 下一 PR 切片为“Automation 事件事实与规则匹配边界”:先分离 WebSocket 事件事实提取、规则匹配和动作计划生成,禁止规则匹配隐式执行外部动作,保留自动化事件优先级与结果状态语义;
|
||||
- 已完成阶段 6 第五个 PR 切片“Automation 事件事实与规则匹配边界”:新增事件事实记录器、无动作副作用的规则匹配器和纯动作计划器;`Center` 与 `Scheduler` 统一通过组件查询规则和生成动作计划,规则匹配不执行外部动作,付款发货动作顺序、规格匹配、延迟快照和恢复语义保持不变;Automation/Server race、全量测试、vet、lint、注释和前端构建门禁通过并合并为一个可回滚提交;
|
||||
- 阶段 6 下一 PR 切片为“Automation 运行协调与动作执行边界”:提取运行创建、动作检查点、延迟恢复和不确定结果隔离的协调组件,保留外部动作已执行/未执行/结果未知三态语义,不改变现有数据库状态机;
|
||||
- 禁止跳过当前入口直接开始 Engine、Automation 或 DB 的大规模拆分。
|
||||
|
||||
## 6. 阶段 0:治理文档与强约束
|
||||
@@ -580,3 +581,4 @@ npm --prefix frontend run build
|
||||
| 2026-08-14 | 完成阶段 6 第二个 PR 切片“Engine WebSocket 连接循环边界” | `registerConnection` 在凭证锁内统一快照复核与 WebSocket 注册,`runConnectionSession` 统一心跳、接收、Token 轮换 goroutine 的创建/取消/等待;`Account` 继续负责凭证错误、风控和重连结果解释;新增会话收束测试,未改变冻结风控行为;全量测试、Engine race、Server race、vet、lint、注释和 diff 门禁通过并合并为一个可回滚提交 | 阶段 6:Engine WebSocket 记录与消息分发边界 |
|
||||
| 2026-08-14 | 完成阶段 6 第三个 PR 切片“Engine WebSocket 记录与消息分发边界” | 新增 `messageDispatcher` 与 `wsRecorder`,分别管理消息去重/防抖/并发投递和 WebSocket 诊断记录队列/worker;`Account` 仅保留 facade 与生命周期接线,动态 Handler、系统事件背压、聊天洪峰限流和 Stop 等待语义保持兼容;Engine 全量回归与并发测试、后续门禁通过并合并为一个可回滚提交 | 阶段 6:Engine 凭证状态与 Token 生命周期边界 |
|
||||
| 2026-08-14 | 完成阶段 6 第四个 PR 切片“Engine 凭证状态与 Token 生命周期边界” | 新增 `credentialState`,集中 Cookie 快照、Token 缓存、刷新锁、设备指纹和刷新诊断状态;运行状态组件锁改名为 `runtimeMu`,保持 `Account` facade 字段访问兼容;Cookie 更新、Token 清理、风控恢复和 WS 注册前凭证快照复核语义保持不变;Engine 全量测试、Engine/Server race、vet、lint、注释和前端构建门禁通过并合并为一个可回滚提交 | 阶段 6:Automation 事件事实与规则匹配边界 |
|
||||
| 2026-08-14 | 完成阶段 6 第五个 PR 切片“Automation 事件事实与规则匹配边界” | 新增 `eventFactRecorder`、`ruleMatcher` 和 `actionPlanner`;事件事实写入、规则查询和动作计划生成职责分离,`Center`/`Scheduler` 不再直接散落调用规则匹配;动作计划保持付款发卡优先、规格过滤和延迟快照语义,新增纯计划与无订单事实回归测试;Automation/Server race、全量测试、vet、lint、注释和前端构建门禁通过并合并为一个可回滚提交 | 阶段 6:Automation 运行协调与动作执行边界 |
|
||||
+26
-106
@@ -86,6 +86,12 @@ type Notifier interface {
|
||||
// Center 是统一自动化处理中心。
|
||||
// 它只接收已经分类好的系统事件或计划任务,不处理用户消息;用户消息由 engine 的回复链处理。
|
||||
type Center struct {
|
||||
// facts 记录已解析的自动化事件事实,不执行规则动作。
|
||||
facts eventFactRecorder
|
||||
// rules 查询适用规则,不执行规则动作。
|
||||
rules ruleMatcher
|
||||
// planner 生成不可变动作计划,不执行外部 I/O。
|
||||
planner actionPlanner
|
||||
store *db.Store
|
||||
senders SenderProvider
|
||||
fetcher OrderDetailFetcher
|
||||
@@ -107,7 +113,16 @@ func New(store *db.Store, senders SenderProvider, logger *slog.Logger) *Center {
|
||||
logger = slog.Default()
|
||||
}
|
||||
client := mtop.NewClient()
|
||||
return &Center{store: store, senders: senders, mtop: client, accountTasks: client, logger: logger.With("subsys", "automation")}
|
||||
return &Center{
|
||||
facts: newEventFactRecorder(store),
|
||||
rules: newRuleMatcher(store),
|
||||
planner: actionPlanner{},
|
||||
store: store,
|
||||
senders: senders,
|
||||
mtop: client,
|
||||
accountTasks: client,
|
||||
logger: logger.With("subsys", "automation"),
|
||||
}
|
||||
}
|
||||
|
||||
// SetMTop 注入 mtop 客户端(确认发货用)。未注入时使用默认 HTTP 实现。
|
||||
@@ -148,7 +163,7 @@ func (c *Center) handleTask(ctx context.Context, task Task) (bool, error) {
|
||||
if task.TriggerType == "" || task.AccountID == "" {
|
||||
return false, nil
|
||||
}
|
||||
if err := c.markEventFacts(ctx, task); err != nil {
|
||||
if err := c.facts.record(ctx, task); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if task.OrderID != "" {
|
||||
@@ -177,25 +192,9 @@ func (c *Center) handleTask(ctx context.Context, task Task) (bool, error) {
|
||||
c.logger.Info("账号已停用,记录事件事实但不执行自动化", "account", task.AccountID, "trigger", task.TriggerType)
|
||||
return false, nil
|
||||
}
|
||||
var rules []db.AutomationRule
|
||||
if resumeRunID := taskAutomationRunID(task); resumeRunID > 0 {
|
||||
run, runErr := c.store.Automation.GetRun(ctx, resumeRunID)
|
||||
if runErr != nil {
|
||||
return false, runErr
|
||||
}
|
||||
if run.Status != "running" {
|
||||
return false, nil
|
||||
}
|
||||
rule, ruleErr := c.store.Automation.Get(ctx, run.RuleID)
|
||||
if ruleErr != nil {
|
||||
return false, ruleErr
|
||||
}
|
||||
rules = []db.AutomationRule{*rule}
|
||||
} else {
|
||||
rules, err = c.store.Automation.Match(ctx, task.AccountID, task.ItemID, task.TriggerType)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
rules, err := c.rules.match(ctx, task)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if len(rules) == 0 {
|
||||
c.logger.Info("无匹配自动化规则,忽略事件", "trigger", task.TriggerType, "order_id", task.OrderID, "item_id", task.ItemID)
|
||||
@@ -323,7 +322,7 @@ func (c *Center) ManualFullDelivery(ctx context.Context, order *db.Order) (int,
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
rules, err := c.store.Automation.Match(ctx, task.AccountID, task.ItemID, TriggerOrderPaid)
|
||||
rules, err := c.rules.match(ctx, task)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -332,10 +331,10 @@ func (c *Center) ManualFullDelivery(ctx context.Context, order *db.Order) (int,
|
||||
}
|
||||
sent := 0
|
||||
for _, rule := range rules {
|
||||
if !hasMatchingSendCard(task, rule.Actions) {
|
||||
if !c.planner.hasMatchingSendCard(task, rule.Actions) {
|
||||
continue
|
||||
}
|
||||
task.ActionPlan = runnableActions(task, immediateManualActions(rule.Actions))
|
||||
task.ActionPlan = c.planner.plan(task, c.planner.immediateManualActions(rule.Actions))
|
||||
rawTask := task
|
||||
rawTask.CookieStr = ""
|
||||
rawJSON, _ := json.Marshal(rawTask)
|
||||
@@ -392,27 +391,10 @@ func (c *Center) ManualFullDelivery(ctx context.Context, order *db.Order) (int,
|
||||
return sent, nil
|
||||
}
|
||||
|
||||
func immediateManualActions(actions []db.AutomationAction) []db.AutomationAction {
|
||||
out := make([]db.AutomationAction, len(actions))
|
||||
copy(out, actions)
|
||||
for i := range out {
|
||||
out[i].DelaySeconds = 0
|
||||
if out[i].ActionType != ActionSendCard {
|
||||
continue
|
||||
}
|
||||
cfg := map[string]any{}
|
||||
_ = json.Unmarshal([]byte(out[i].ConfigJSON), &cfg)
|
||||
cfg["delay_override"] = true
|
||||
raw, _ := json.Marshal(cfg)
|
||||
out[i].ConfigJSON = string(raw)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (c *Center) executeRule(ctx context.Context, task Task, rule db.AutomationRule) error {
|
||||
var err error
|
||||
if len(task.ActionPlan) == 0 && task.TriggerType != TriggerOrderPaid {
|
||||
task.ActionPlan = runnableActions(task, rule.Actions)
|
||||
task.ActionPlan = c.planner.plan(task, rule.Actions)
|
||||
}
|
||||
task, err = c.prepareTask(ctx, task)
|
||||
if err != nil {
|
||||
@@ -423,7 +405,7 @@ func (c *Center) executeRule(ctx context.Context, task Task, rule db.AutomationR
|
||||
return nil
|
||||
}
|
||||
if len(task.ActionPlan) == 0 {
|
||||
task.ActionPlan = runnableActions(task, rule.Actions)
|
||||
task.ActionPlan = c.planner.plan(task, rule.Actions)
|
||||
}
|
||||
retryTask := task
|
||||
retryTask.CookieStr = ""
|
||||
@@ -472,7 +454,7 @@ func (c *Center) executeRule(ctx context.Context, task Task, rule db.AutomationR
|
||||
}
|
||||
}()
|
||||
actions := task.ActionPlan
|
||||
if task.TriggerType == TriggerOrderPaid && !hasMatchingSendCard(task, actions) {
|
||||
if task.TriggerType == TriggerOrderPaid && !c.planner.hasMatchingSendCard(task, actions) {
|
||||
status, errMsg = "failed", "未匹配到订单规格对应的卡密动作"
|
||||
return errors.New(errMsg)
|
||||
}
|
||||
@@ -527,29 +509,6 @@ func (c *Center) executeRule(ctx context.Context, task Task, rule db.AutomationR
|
||||
return nil
|
||||
}
|
||||
|
||||
func runnableActions(task Task, actions []db.AutomationAction) []db.AutomationAction {
|
||||
out := make([]db.AutomationAction, 0, len(actions))
|
||||
if task.TriggerType == TriggerOrderPaid {
|
||||
for _, action := range actions {
|
||||
if action.Enabled && action.ActionType == ActionSendCard && actionMatchesOrderSpec(task, action) {
|
||||
out = append(out, action)
|
||||
}
|
||||
}
|
||||
for _, action := range actions {
|
||||
if action.Enabled && action.ActionType == ActionConfirmShipment {
|
||||
out = append(out, action)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
for _, action := range actions {
|
||||
if action.Enabled {
|
||||
out = append(out, action)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (c *Center) executeRunActions(ctx context.Context, task Task, ruleID int64, run *db.AutomationRun, actions []db.AutomationAction, skipDelays bool) (int, bool, error) {
|
||||
sent := run.SentCount
|
||||
for cursor := run.ActionCursor; cursor < len(actions); cursor++ {
|
||||
@@ -660,15 +619,6 @@ func (c *Center) notifyRunNeedsReview(run db.AutomationRun, reason string) {
|
||||
c.notifyResult(task, "needs_review", run.SentCount, "需要人工核对:"+reason)
|
||||
}
|
||||
|
||||
func hasMatchingSendCard(task Task, actions []db.AutomationAction) bool {
|
||||
for _, action := range actions {
|
||||
if action.Enabled && action.ActionType == ActionSendCard && actionMatchesOrderSpec(task, action) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// actionDelaySeconds 统一卡密默认延时和动作覆盖语义。旧动作没有
|
||||
// delay_override 字段时自动使用卡密上的默认延时。
|
||||
func (c *Center) actionDelaySeconds(ctx context.Context, action db.AutomationAction) (int, error) {
|
||||
@@ -1161,36 +1111,6 @@ func (c *Center) cookieValue(ctx context.Context, cookieID string) (string, erro
|
||||
return value, nil
|
||||
}
|
||||
|
||||
func (c *Center) markEventFacts(ctx context.Context, task Task) error {
|
||||
if task.OrderID == "" {
|
||||
return nil
|
||||
}
|
||||
if err := c.store.Orders.Upsert(ctx, task.OrderID, db.OrderUpsertOpts{
|
||||
CookieID: task.AccountID,
|
||||
ItemID: task.ItemID,
|
||||
BuyerID: task.BuyerID,
|
||||
ChatID: task.ChatID,
|
||||
OrderStatus: task.OrderStatus,
|
||||
SpecName: task.SpecName,
|
||||
SpecValue: task.SpecValue,
|
||||
Quantity: task.Quantity,
|
||||
Amount: task.Amount,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("记录自动化事件订单事实: %w", err)
|
||||
}
|
||||
switch task.TriggerType {
|
||||
case TriggerOrderPaid:
|
||||
if err := c.store.Automation.MarkOrderEventTime(ctx, task.OrderID, "paid_at"); err != nil {
|
||||
return fmt.Errorf("记录订单付款时间: %w", err)
|
||||
}
|
||||
case TriggerBuyerReviewed:
|
||||
if err := c.store.Automation.MarkOrderEventTime(ctx, task.OrderID, "buyer_reviewed_at"); err != nil {
|
||||
return fmt.Errorf("记录买家评价时间: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func buildTriggerKey(task Task) string {
|
||||
if task.TriggerType == TriggerReviewMissingTimeout && task.OrderID != "" {
|
||||
if attempt, ok := task.Raw["attempt"]; ok {
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
package automation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"xianyu-go/internal/db"
|
||||
)
|
||||
|
||||
// eventFactRecorder 只负责把已经解析出的事件事实写入持久化层。
|
||||
// 它不读取规则、不创建运行记录,也不执行任何外部动作。
|
||||
type eventFactRecorder struct {
|
||||
// store 提供订单事实和事件时间的持久化能力。
|
||||
store *db.Store
|
||||
}
|
||||
|
||||
// newEventFactRecorder 构造事件事实记录组件。
|
||||
func newEventFactRecorder(store *db.Store) eventFactRecorder {
|
||||
return eventFactRecorder{store: store}
|
||||
}
|
||||
|
||||
// record 将自动化任务中的订单字段和触发时间写入事实表。
|
||||
func (r eventFactRecorder) record(ctx context.Context, task Task) error {
|
||||
if r.store == nil || r.store.Orders == nil || r.store.Automation == nil || task.OrderID == "" {
|
||||
return nil
|
||||
}
|
||||
if err := r.store.Orders.Upsert(ctx, task.OrderID, db.OrderUpsertOpts{
|
||||
CookieID: task.AccountID,
|
||||
ItemID: task.ItemID,
|
||||
BuyerID: task.BuyerID,
|
||||
ChatID: task.ChatID,
|
||||
OrderStatus: task.OrderStatus,
|
||||
SpecName: task.SpecName,
|
||||
SpecValue: task.SpecValue,
|
||||
Quantity: task.Quantity,
|
||||
Amount: task.Amount,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("记录自动化事件订单事实: %w", err)
|
||||
}
|
||||
switch task.TriggerType {
|
||||
case TriggerOrderPaid:
|
||||
if err := r.store.Automation.MarkOrderEventTime(ctx, task.OrderID, "paid_at"); err != nil {
|
||||
return fmt.Errorf("记录订单付款时间: %w", err)
|
||||
}
|
||||
case TriggerBuyerReviewed:
|
||||
if err := r.store.Automation.MarkOrderEventTime(ctx, task.OrderID, "buyer_reviewed_at"); err != nil {
|
||||
return fmt.Errorf("记录买家评价时间: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ruleMatcher 只查询适用于任务的规则,不执行规则动作或修改运行状态。
|
||||
type ruleMatcher struct {
|
||||
// store 提供规则查询和恢复运行读取能力。
|
||||
store *db.Store
|
||||
}
|
||||
|
||||
// newRuleMatcher 构造无动作副作用的规则匹配组件。
|
||||
func newRuleMatcher(store *db.Store) ruleMatcher {
|
||||
return ruleMatcher{store: store}
|
||||
}
|
||||
|
||||
// match 查询普通事件或恢复运行对应的规则快照。
|
||||
func (m ruleMatcher) match(ctx context.Context, task Task) ([]db.AutomationRule, error) {
|
||||
if m.store == nil || m.store.Automation == nil {
|
||||
return nil, nil
|
||||
}
|
||||
if runID := taskAutomationRunID(task); runID > 0 {
|
||||
run, err := m.store.Automation.GetRun(ctx, runID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if run.Status != "running" {
|
||||
return nil, nil
|
||||
}
|
||||
rule, err := m.store.Automation.Get(ctx, run.RuleID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if rule == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return []db.AutomationRule{*rule}, nil
|
||||
}
|
||||
return m.store.Automation.Match(ctx, task.AccountID, task.ItemID, task.TriggerType)
|
||||
}
|
||||
|
||||
// actionPlanner 只根据任务事实和规则动作生成不可变的动作计划。
|
||||
// 计划过程不得访问数据库、发送网络请求或修改规则。
|
||||
type actionPlanner struct{}
|
||||
|
||||
// plan 根据触发类型筛选可执行动作,并保留付款事件的发卡优先顺序。
|
||||
func (actionPlanner) plan(task Task, actions []db.AutomationAction) []db.AutomationAction {
|
||||
out := make([]db.AutomationAction, 0, len(actions))
|
||||
if task.TriggerType == TriggerOrderPaid {
|
||||
for _, action := range actions {
|
||||
if action.Enabled && action.ActionType == ActionSendCard && actionMatchesOrderSpec(task, action) {
|
||||
out = append(out, action)
|
||||
}
|
||||
}
|
||||
for _, action := range actions {
|
||||
if action.Enabled && action.ActionType == ActionConfirmShipment {
|
||||
out = append(out, action)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
for _, action := range actions {
|
||||
if action.Enabled {
|
||||
out = append(out, action)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// hasMatchingSendCard 判断付款事件是否存在匹配当前规格的发卡动作。
|
||||
func (actionPlanner) hasMatchingSendCard(task Task, actions []db.AutomationAction) bool {
|
||||
for _, action := range actions {
|
||||
if action.Enabled && action.ActionType == ActionSendCard && actionMatchesOrderSpec(task, action) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// immediateManualActions 复制动作并清除延迟,供明确的人工完整发货使用。
|
||||
func (actionPlanner) immediateManualActions(actions []db.AutomationAction) []db.AutomationAction {
|
||||
out := make([]db.AutomationAction, len(actions))
|
||||
copy(out, actions)
|
||||
for i := range out {
|
||||
out[i].DelaySeconds = 0
|
||||
if out[i].ActionType != ActionSendCard {
|
||||
continue
|
||||
}
|
||||
config := map[string]any{}
|
||||
_ = json.Unmarshal([]byte(out[i].ConfigJSON), &config)
|
||||
config["delay_override"] = true
|
||||
raw, _ := json.Marshal(config)
|
||||
out[i].ConfigJSON = string(raw)
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package automation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"xianyu-go/internal/db"
|
||||
)
|
||||
|
||||
// TestActionPlannerPaidEventKeepsCardBeforeShipment 验证付款事件只生成匹配卡密动作并保持发货顺序。
|
||||
func TestActionPlannerPaidEventKeepsCardBeforeShipment(t *testing.T) {
|
||||
// task 是包含规格事实的付款事件。
|
||||
task := Task{TriggerType: TriggerOrderPaid, SpecName: "颜色", SpecValue: "蓝", Quantity: "2"}
|
||||
// actions 是待匹配的规则动作,故意包含一个规格不匹配的卡密动作。
|
||||
actions := []db.AutomationAction{
|
||||
{ID: 1, ActionType: ActionConfirmShipment, Enabled: true},
|
||||
{ID: 2, ActionType: ActionSendCard, Enabled: true, ConfigJSON: `{"spec_name":"颜色","spec_value":"蓝"}`},
|
||||
{ID: 3, ActionType: ActionSendCard, Enabled: true, ConfigJSON: `{"spec_name":"颜色","spec_value":"红"}`},
|
||||
}
|
||||
// original 用于确认规划过程不会修改规则动作输入。
|
||||
original := append([]db.AutomationAction(nil), actions...)
|
||||
// planner 是不执行外部 I/O 的纯动作计划组件。
|
||||
planner := actionPlanner{}
|
||||
// plan 是按发卡优先规则生成的不可变动作快照。
|
||||
plan := planner.plan(task, actions)
|
||||
if got := []int64{plan[0].ID, plan[1].ID}; !reflect.DeepEqual(got, []int64{2, 1}) {
|
||||
t.Fatalf("付款事件动作顺序=%v,want [2 1]", got)
|
||||
}
|
||||
if !reflect.DeepEqual(actions, original) {
|
||||
t.Fatal("动作计划不应修改规则动作输入")
|
||||
}
|
||||
}
|
||||
|
||||
// TestEventFactRecorderWithoutOrderIsNoOp 验证没有订单事实时记录组件不执行任何持久化动作。
|
||||
func TestEventFactRecorderWithoutOrderIsNoOp(t *testing.T) {
|
||||
// recorder 未注入数据库时应对无订单任务安全忽略。
|
||||
recorder := newEventFactRecorder(nil)
|
||||
if err := recorder.record(context.Background(), Task{AccountID: "cid", TriggerType: TriggerBuyerReviewed}); err != nil {
|
||||
t.Fatalf("无订单事实应安全忽略,err=%v", err)
|
||||
}
|
||||
}
|
||||
@@ -89,7 +89,7 @@ func (s *Scheduler) scan(ctx context.Context) {
|
||||
waitingForWS[order.CookieID]++
|
||||
continue
|
||||
}
|
||||
rules, err := s.center.store.Automation.Match(ctx, order.CookieID, order.ItemID, TriggerReviewMissingTimeout)
|
||||
rules, err := s.center.rules.match(ctx, Task{AccountID: order.CookieID, ItemID: order.ItemID, TriggerType: TriggerReviewMissingTimeout})
|
||||
if err != nil {
|
||||
s.center.logger.Warn("查询求评价自动化规则失败", "account", order.CookieID, "order_id", order.OrderID, "item_id", order.ItemID, "err", err)
|
||||
continue
|
||||
@@ -185,7 +185,7 @@ func (s *Scheduler) runRecoveryTasks(ctx context.Context) {
|
||||
func recoveryNeedsSender(task Task, rule db.AutomationRule, cursor int) bool {
|
||||
actions := task.ActionPlan
|
||||
if len(actions) == 0 {
|
||||
actions = runnableActions(task, rule.Actions)
|
||||
actions = (actionPlanner{}).plan(task, rule.Actions)
|
||||
}
|
||||
if cursor < 0 || cursor >= len(actions) {
|
||||
return false
|
||||
|
||||
Reference in new issue
Block a user