このトピックでは、fail ステップについて説明し、その使用法の例を示します。
概要
fail ステップは、ステップのシーケンスを早期に終了させます。これは、プログラミング言語における raise や throw のような操作に似ています。フローが fail ステップを実行すると、後続のステップは実行されません。fail ステップは、その親ステップを失敗させます。この失敗は上方に伝播し、最終的にフロー全体が失敗します。
fail ステップには、次のプロパティがあります。
- (必須) type:ステップのタイプ。値は
failにする必要があります。 - (必須) name:ステップの名前。
- (オプション) error:フォルトのタイプ。
- (オプション) cause:フォルトの理由。
- (オプション) inputMappings:入力マッピング。
- (オプション) outputMappings:出力マッピング。
例
次のフロー定義では、fail ステップを使用してフロー実行を早期に終了します。
- 入力の
statusがreadyの場合、フローは最初の choice ブランチのpass1ステップを実行し、その後finalステップを実行します。 - 入力の
statusがfailedの場合、フローは 2 番目の choice ブランチのgoto指示に従い、handle_failureステップを実行します。handle_failureは fail ステップであるため、フローはhandle_failureの後にfinalステップを実行しません。 - 入力に
statusが含まれていない場合、またはstatusがreadyでもfailedでもない場合、フローは、デフォルトブランチのpass2ステップを実行し、次にhandle_failureステップを実行します。
version: v1
type: flow
steps:
- type: choice
name: mychoice
choices:
- condition: $.status == "ready"
# ステップを持つ choice
steps:
- type: pass
name: pass1
goto: final
- condition: $.status == "failed"
goto: handle_failure
default:
# goto を使用する必要はありません
steps:
- type: pass
name: pass2
- type: fail
name: handle_failure
error: StatusIsNotReady
cause: status is not ready
- type: pass
name: final