fix(fulfillment): 允许有效快照恢复 source_cancelled 任务
- 先到的停用配置快照可能把任务取消,后到的启用快照此前被终态拦截 - 仅 source_cancelled 且新快照有效时恢复,用户取消/完成仍保持终态 - 补充恢复测试
This commit is contained in:
@@ -217,11 +217,6 @@ def _upsert_order_snapshot(
|
||||
task.issue_code,
|
||||
)
|
||||
_apply_customer_profile(task, snapshot)
|
||||
if task.execution_status in {"completed", "cancelled"}:
|
||||
task.source_snapshot_json = _jsonable(snapshot)
|
||||
return task, created, False
|
||||
|
||||
previous_execution_status = task.execution_status
|
||||
terminal = (
|
||||
terminal_order
|
||||
or _snapshot_value(
|
||||
@@ -246,6 +241,30 @@ def _upsert_order_snapshot(
|
||||
)
|
||||
is False
|
||||
)
|
||||
if task.execution_status in {"completed", "cancelled"}:
|
||||
# 历史“停用配置”的旧快照可能先到,随后开启配置的新快照又到;
|
||||
# 系统原因取消的任务允许被后续有效快照恢复。用户取消/完成的仍保持终态。
|
||||
if (
|
||||
task.execution_status == "cancelled"
|
||||
and task.issue_code == "source_cancelled"
|
||||
and not terminal
|
||||
):
|
||||
task.execution_status = "pending_mapping"
|
||||
task.issue_code = ""
|
||||
task.last_error = ""
|
||||
task.next_allocate_at = None
|
||||
task.completed_at = None
|
||||
_append_event(
|
||||
db,
|
||||
task.id,
|
||||
"source_order_restored",
|
||||
detail={"reason": "valid_snapshot_after_source_cancel"},
|
||||
)
|
||||
else:
|
||||
task.source_snapshot_json = _jsonable(snapshot)
|
||||
return task, created, False
|
||||
|
||||
previous_execution_status = task.execution_status
|
||||
|
||||
task.platform_order_id = str(
|
||||
_snapshot_value(snapshot, "platformOrderId", "platform_order_id", default="")
|
||||
|
||||
Reference in New Issue
Block a user