>>操作员如何在Airflow中定义任务依赖性?

ida*_*ika 7 python airflow

我正在阅读Apache Airflow教程https://github.com/hgrif/airflow-tutorial,并遇到了本节中的定义任务依赖项。

with DAG('airflow_tutorial_v01',
     default_args=default_args,
     schedule_interval='0 * * * *',
     ) as dag:

print_hello = BashOperator(task_id='print_hello',
                           bash_command='echo "hello"')
sleep = BashOperator(task_id='sleep',
                     bash_command='sleep 5')
print_world = PythonOperator(task_id='print_world',
                             python_callable=print_world)


print_hello >> sleep >> print_world
Run Code Online (Sandbox Code Playgroud)

令我困惑的是

print_hello >> sleep >> print_world
Run Code Online (Sandbox Code Playgroud)

>>在Python中是什么意思?我知道按位运算符,但不能与此处的代码相关。

小智 7

气流将工作流表示为有向无环图。工作流是必须并行或顺序执行的任意数量的任务。“ >>”是Airflow语法,用于将任务设置为另一个任务的下游。

进入孵化器气流项目存储库,models.py在该airflow目录中定义了Airflow的许多高级抽象的行为。如果愿意,可以深入研究其他类,但是回答您问题的一个是BaseOperator类。Airflow中的所有运算符都继承自BaseOperator。__rshift__BaseOperator类的方法在设置任务或另一个任务的DAG的上下文中实现Python右移逻辑运算符。

在此处查看实现。

  • 该行的链接进入主分支。我建议选择一个特定的分支,以便版本更改不会影响链接。 (2认同)