図 2.TriggerDagRunOperator を使用して DAG 内で DAG をトリガーできます(クリックして拡大)
このワークフローで、ブロック dag_1 と dag_2 は、Cloud Composer 環境の別の DAG でグループ化された一連のタスクを表します。
このワークフローを実装するには、2 つの個別の DAG ファイルが必要です。制御 DAG ファイルは次のようになります。
fromairflowimportDAGfromairflow.operators.dummyimportDummyOperatorfromairflow.operators.trigger_dagrunimportTriggerDagRunOperatorfromairflow.utils.datesimportdays_agowithDAG(dag_id="controller_dag_to_trigger_other_dags",default_args={"owner":"airflow"},start_date=days_ago(1),schedule_interval="@once",)asdag:start=DummyOperator(task_id="start")trigger_1=TriggerDagRunOperator(task_id="dag_1",trigger_dag_id="dag-to-trigger",# Ensure this equals the dag_id of the DAG to triggerconf={"message":"Hello World"},)trigger_2=TriggerDagRunOperator(task_id="dag_2",trigger_dag_id="dag-to-trigger",# Ensure this equals the dag_id of the DAG to triggerconf={"message":"Hello World"},)some_other_task=DummyOperator(task_id="some-other-task")end=DummyOperator(task_id="end")start >> trigger_1 >> some_other_task >> trigger_2 >> end
fromairflow.models.dagimportDAGfromairflow.operators.bashimportBashOperatorfromairflow.operators.dummyimportDummyOperatorfromairflow.utils.datesimportdays_agofromairflow.utils.task_groupimportTaskGroupwithDAG(dag_id="taskgroup_example",start_date=days_ago(1))asdag:start=DummyOperator(task_id="start")withTaskGroup("taskgroup_1",tooltip="task group #1")assection_1:task_1=BashOperator(task_id="op-1",bash_command=":")task_2=BashOperator(task_id="op-2",bash_command=":")withTaskGroup("taskgroup_2",tooltip="task group #2")assection_2:task_3=BashOperator(task_id="op-3",bash_command=":")task_4=BashOperator(task_id="op-4",bash_command=":")some_other_task=DummyOperator(task_id="some-other-task")end=DummyOperator(task_id="end")start >> section_1 >> some_other_task >> section_2 >> end
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-02-18 UTC。"],[[["This document outlines methods for grouping tasks within Airflow pipelines, covering approaches like structuring relationships in the DAG graph, triggering child DAGs from a parent DAG, and utilizing the `TaskGroup` operator."],["Grouping tasks directly in the DAG graph is achieved by defining relationships between tasks, demonstrated with the syntax `start \u003e\u003e [task_1, task_2]`, which executes `task_1` and `task_2` concurrently after `start`."],["Parent DAGs can trigger child DAGs using the `TriggerDagRunOperator`, requiring the `trigger_dag_id` to match the `dag_id` of the child DAG."],["The `TaskGroup` operator allows for grouping tasks within a DAG, which provides a visual organization in the Airflow UI and simplifies complex workflows."],["It is recommended to avoid using SubDAGs for grouping tasks due to performance and functional issues; the document presents superior alternative methods for structuring workflows."]]],[]]