每个任务的依赖关系都必须指定,以确保它们在正确的顺序下运行。如下示例:
from airflow import DAG from airflow.operators.python_operator import PythonOperator from datetime import datetime
default_args = { 'owner': 'airflow', 'depends_on_past': False, 'start_date': datetime(2021, 1, 1), } dag = DAG('example_dag', default_args=default_args)
def task_one(): print('Task one executed')
def task_two(): print('Task two executed')
def task_three(): print('Task three executed')
t1 = PythonOperator( task_id='task_one', python_callable=task_one, dag=dag )
t2 = PythonOperator( task_id='task_two', python_callable=task_two, dag=dag )
t3 = PythonOperator( task_id='task_three', python_callable=task_three, dag=dag )
t1 >> t2 >> t3 # 指定任务之间的依赖关系
在DAG中指定任务的顺序,以确保它们按正确的顺序运行。如下示例:
from airflow import DAG from airflow.operators.python_operator import PythonOperator from datetime import datetime
default_args = { 'owner': 'airflow', 'depends_on_past': False, 'start_date': datetime(2021, 1, 1), } dag = DAG('example_dag', default_args=default_args)
def task_one(): print('Task one executed')
def task_two(): print('Task two executed')
def task_three(): print('Task three executed')
t1 = PythonOperator( task_id='task_one', python_callable=task_one, dag=dag )
t2 = PythonOperator( task_id='task_two', python_callable=task_two, dag=dag