气流:如何在非PythonOperator中使用xcom_push和xcom_pull [英] Airflow: how to use xcom_push and xcom_pull in non-PythonOperator

查看:480
本文介绍了气流:如何在非PythonOperator中使用xcom_push和xcom_pull的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到很多关于如何在Airflow中将 xcom_push xcom_pull 与PythonOperators结合使用的示例。

I see a lot of examples on how to use xcom_push and xcom_pull with PythonOperators in Airflow.

我需要从 non-PythonOperator 类执行 xcom_pull ,并且不能找到方法。

I need to do xcom_pull from a non-PythonOperator class and couldn't find how to do it.

任何指针或示例都会受到赞赏!

Any pointer or example will be appreciated!

推荐答案

您可以从模板字段中访问XCom变量。例如,要从XCom中进行读取:

You can access XCom variables from within templated fields. For example, to read from XCom:

myOperator = MyOperator(
    message="Operation result: {{ task_instance.xcom_pull(task_ids=['task1', 'task2'], key='result_status') }}",
    ...

也可以不指定任务,以在一个具有相同键名的DagRun中获得所有XCom推送

It is also possible to not specify task to get all XCom pushes within one DagRun with the same key name

myOperator = MyOperator(
    message="Warning status: {{ task_instance.xcom_pull(task_ids=None, key='warning_status') }}",
    ...

将返回数组。

这篇关于气流:如何在非PythonOperator中使用xcom_push和xcom_pull的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆