补齐任务幂等并发保护
新增三数据库任务幂等登记迁移,在任务创建事务中防止重复幂等键,并补充并发回归测试与进度清单。
This commit is contained in:
1 parent
163b3e9c5d
commit
7e14bbf42f
11 files changed
+168
-5
No files matched your search
@@ -127,6 +127,17 @@ func (r *SQLTaskRepository) CreateTask(ctx context.Context, item Task) error {
|
||||
if err := validateTaskInsertResult(result); err != nil {
|
||||
return err
|
||||
}
|
||||
if item.IdempotencyKey != "" {
|
||||
idempotencyResult, idempotencyErr := tx.ExecContext(ctx, r.query(`INSERT INTO task_idempotency
|
||||
(domain_id, idempotency_key, task_id, created_at) VALUES (?, ?, ?, ?)`),
|
||||
item.DomainID, item.IdempotencyKey, item.ID, now)
|
||||
if idempotencyErr != nil {
|
||||
return fmt.Errorf("创建任务幂等记录失败:%w", idempotencyErr)
|
||||
}
|
||||
if err := validateTaskInsertResult(idempotencyResult); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := tx.Commit(); err != nil {
|
||||
return fmt.Errorf("提交任务创建事务失败:%w", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user