guan404ming commented on code in PR #74069:
URL: https://github.com/apache/airflow/pull/74069#discussion_r4198208517
##########
ts-sdk/adr/0002-native-dag-interface.md:
##########
@@ -135,6 +135,48 @@ data is the wiring object itself — `summarize({ north:
extractNorth(), south:
does. This matches `Before`/`After` in the Go SDK's native Dag interface,
spelled to TypeScript
convention.
+### Conditional branching: `if` and `else`
+
+`dag.if(handler)` is TypeScript's spelling of the construct
+[`airflow-core/adr/lang-sdk/0008`](../../airflow-core/adr/lang-sdk/0008-control-flow-constructs.md)
+names after the host language's control flow:
+
+```ts
+async function hasRows({ rows }: { rows: number }): Promise<boolean> {
+ return rows > 0;
+}
+
+const gate = dag.if(hasRows, { rows: validated });
+gate.then(loadIfReady).else(loadFallback);
Review Comment:
Good point, `dag.if` and `dag.switch` now take a trailing `TaskSpec`, as
Go's `dag.If` does: `dag.if(fn, inputs?, spec?)`.
##########
airflow-core/docs/authoring-and-scheduling/language-sdks/typescript.rst:
##########
@@ -359,6 +359,34 @@ there. Set it once on the Dag and each task inherits it:
``queue`` on a task wins over the Dag's. See
:ref:`typescript-sdk/coordinator-config` for the
``queue_to_coordinator`` entry that sends that queue to the coordinator.
+Conditional branching
+~~~~~~~~~~~~~~~~~~~~~
+
+``dag.if`` takes a handler that returns a boolean, and names the task each
outcome runs:
+
+.. code-block:: typescript
+
+ async function hasRows({ rows }: { rows: number }): Promise<boolean> {
+ return rows > 0;
+ }
+
+ const gate = dag.if(hasRows)({ rows: extracted });
Review Comment:
Following Pierre's suggestion, the task id now goes in the trailing spec (`{
taskId }`), matching Go's `TaskSpec{TaskID}`, so I dropped the positional id.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]