WaitFor Failure Recovery
在 WaitFor 耗尽重试策略后进行恢复。
WaitForFailureRecoveryFlow 从 FailingStep 开始。它的 WaitFor 方法返回要等待的间隔,但示例有意让该方法失败。WaitForRetry 耗尽后,其 WaitForFailure 策略继续到 FailingStep.Execute。Execute 从上下文读取等待失败信息,再转到 RecoveryStep,后者完成 Flow。
当失败的条件查询可以恢复,而且 Flow 可以在普通 Step 代码中决定下一步时,使用此模式。
class FailingStep(Step[str]):
def get_step_options(self) -> StepOptions:
return StepOptions(
wait_for_retry=RetryPolicy(maximum_attempts=2),
wait_for_failure=WaitForFailurePolicy.PROCEED,
)
def wait_for(self, context: Context, input: str) -> Wait:
raise RuntimeError("planned WaitFor failure")
def execute(self, context: Context, input: str) -> StepDecision:
if not context.wait_for_method_failed():
raise RuntimeError("waitFor failure was not reported")
return go_to(RecoveryStep, input)
class RecoveryStep(Step[str]):
def execute(self, context: Context, input: str) -> StepDecision:
return graceful_complete(f"recovered {input}")
例子: examples/python/dex_examples/primitives/proceed_on_wait_failure/proceed_on_wait_failure_flow.py