You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -83,6 +83,106 @@ Assuming _Upon Failure_ activity and _Dummy Upon Failure_ activity succeed,
83
83
* When previous activity succeeds: node _Dummy Upon Skip_ is skipped and its parent node _Upon Success_ succeeds; the other node activity, _Upon Failure_, is skipped and its parent node succeeds; overall pipeline succeeds
84
84
* When previous activity fails: node _Upon Failure_ succeeds and _Dummy Upon Skip_ succeeds; overall pipeline succeeds
85
85
86
+
87
+
## Conditional execution
88
+
89
+
As we develop more complicated and resilient pipelines, it's sometimes required to introduced conditional executions to our logic: execute a certain activity only if certain conditions are met. The use cases are plenty, for instance:
90
+
91
+
* run a follow-up activity, such as sending an email notification, if previous copy jobs succeeded
92
+
* run an error handling job, if any of the previous activities failed
93
+
* proceed to the next step if either the activity itself or its corresponding error handling activity succeeds
94
+
* etc.
95
+
96
+
Here we explain some common logics and how to implement them in ADF.
97
+
98
+
### Single activity
99
+
Here are some common patterns following a single activity. We can use these patterns as building blocks to construct complicated work flows.
100
+
101
+
#### Error handling
102
+
The pattern is the most common condition logic in ADF. An error handling activity is defined for the "Upon Failure" path, and will be invoked if the main activity fails. It should be incorporated as best practice for all mission critical steps that needs fall-back alternatives or logging.
Certain steps, such as informational logging, are less critical, and their failures shouldn't block the whole pipeline. In such cases, we should adopt the best effort strategies: adding next steps to the "Upon Completion" path, to unblock the work flow.
108
+
109
+
:::image type="content" source="media/tutorial-pipeline-failure-error-handling/conditional-simple-2.png" alt-text="Screenshot showcasing best effort attempt to log.":::
110
+
111
+
### And
112
+
First and most common scenarios are conditional "and": continue the pipeline if and only if the previous activities succeed. For instance, you may have multiple copy activities that need to succeed first before moving onto next stage of data processing. In ADF, the behavior can be achieved easily: declare multiple dependencies for the next step. Graphically, that means multiple lines pointing into the next activity. You can choose either "Upon Success" path to ensure the dependency have succeeded, or "Upon Completion" path to allow best effort execution.
113
+
114
+
Here, the follow-up wait activity will only execute when both web activities were successful.
115
+
116
+
:::image type="content" source="media/tutorial-pipeline-failure-error-handling/conditional-and-1.png" alt-text="Screenshot showcasing pipeline proceeds only if both web activities succeed.":::
117
+
118
+
And here, the follow-up wait activity will execute when _ActivitySucceeded_ passes and _ActivityFailed_ completed. Note, with "Upon Success" path _ActivitySucceeded_ has to succeed, whereas _ActivityFailed_ on the "Upon Completion" path runs with best effort, that is, may fail.
119
+
120
+
121
+
:::image type="content" source="media/tutorial-pipeline-failure-error-handling/conditional-and-2.png" alt-text="Screenshot showcasing pipeline proceeds when first web activity succeeds and second web activity completes.":::
122
+
123
+
### Or
124
+
Second common scenarios are conditional "or": run an activity if any of the dependencies succeeds or fails. Here we need to use "Upon Completion" paths, [If Condition activity](control-flow-if-condition-activity.md) and [expression language](control-flow-expression-language-functions.md).
125
+
126
+
Before we dive deep into code, we need to understand one more thing. After an activity ran and completed, you may reference its status with _@activity('ActivityName').Status_. It will be either _"Succeeded"_ or _"Failed"_. We'll use this property to build conditional or logic.
127
+
128
+
#### Shared error handling logging step
129
+
In some cases, you may want to invoke a shared error handling or logging step, if any of the previous activities failed. You can build your pipeline like this:
130
+
* run multiple activities in parallel
131
+
* add an if condition to contain the error handling steps, in True branch
132
+
* connect activities to the condition activity using _"Upon Completion"_ path
:::image type="content" source="media/tutorial-pipeline-failure-error-handling/conditional-or-1.png" alt-text="Screenshot showcasing how to execute a shared error handling step if any of the previous activities failed.":::
143
+
144
+
#### Greenlight if any activity succeeded
145
+
When all your activities are best effort, you may want to proceed to next step if any of the previous activities succeeded. You can build your pipeline like this:
146
+
* run multiple activities in parallel
147
+
* add an if condition to contain next steps, in True branch
148
+
* connect activities to the condition activity using _"Upon Completion"_ path
* Note: the graph will look exactly like the previous scenario. The only difference is the expression language used
154
+
155
+
:::image type="content" source="media/tutorial-pipeline-failure-error-handling/conditional-or-2.png" alt-text="Screenshot showcasing pipeline proceeds to next step if any of the activities pass.":::
156
+
157
+
### Complex scenarios
158
+
#### All activities need to succeed to proceed
159
+
The pattern is a combination of two: conditional and + error handling. The pipeline proceeds to next steps if all proceeding activities succeed, or else it runs a shared error logging step. You can build the pipeline like this:
160
+
* run multiple activities in parallel
161
+
* add an if condition. Add next steps in True branch, and add error handling code in False branch
162
+
* connect activities to the condition activity using _"Upon Completion"_ path
:::image type="content" source="media/tutorial-pipeline-failure-error-handling/conditional-complex-1.png" alt-text="Screenshot showcasing pipeline proceeds to next step if any of the activities pass, or else runs error handling code.":::
169
+
170
+
171
+
#### Try-Catch-Proceed
172
+
The pattern is equivalent to try catch block in coding. It states that if either the activity or the error handling code succeeds, the pipeline should proceed. It's rather complicated and should only be reserved for the most mission critical steps.
173
+
* add the mission critical work step
174
+
* add an error handling activity to the _"Upon Failure"_ path of the main activity
175
+
* add an if condition to contain next steps, in True branch
176
+
* connect _"Upon Completion"_ path of the main activity to the condition activity
177
+
* connect both _"Upon Success"_ and _"Upon Skip"_ paths of the error handling activity to the condition activity
0 commit comments