Manual Recovery
在自动重试耗尽后,将 Step 升级给人工处理。
ManualRecoveryFlow 从 DoWorkStep 开始。它的失败策略执行三次指数退避重试,然后转到 ManualStep。ManualStep 等待 Retry Channel 或 Skip Channel。操作人员解决问题后,Retry 回到 DoWorkStep;Skip 使用明确原因使 Flow 失败。
核心实现
每个示例都定义了重试策略和操作人员决策。可运行示例注册 Flow,并提供 HTTP 启动端点。
class DoWorkStep(Step[bool]):
def get_step_options(self) -> StepOptions:
return StepOptions(
execute_retry=RetryPolicy(
initial_interval=timedelta(seconds=1),
backoff_coefficient=2.0,
maximum_interval=timedelta(seconds=4),
maximum_attempts=4,
)
).on_execute_failure_proceed_to(ManualStep)
def execute(self, context: Context, should_fail: bool) -> StepDecision:
if should_fail:
raise RuntimeError("work failed")
return graceful_complete("work completed")
class ManualStep(Step[bool]):
def wait_for(self, context: Context, input: bool) -> Wait:
return Wait.any_of(
retry_channel.for_one(),
skip_channel.for_one(),
)
def execute(self, context: Context, input: bool) -> StepDecision:
if retry_channel.results(context):
return go_to(DoWorkStep, False)
return force_fail("manual recovery skipped")
例子: examples/python/dex_examples/patterns/intervention/manual_recovery_flow.py