首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用python运算符在气流dag文件中使用xCom?

如何使用python运算符在气流dag文件中使用xCom?
EN

Stack Overflow用户
提问于 2018-08-16 23:59:27
回答 1查看 6.7K关注 0票数 -1

我正在处理这个airflow dag文件,以便使用XCOM进行一些测试,但不确定如何在python操作符之间使用它。有没有人能帮我写一下如何使用XCOM的推拉函数在python操作符之间传递消息的逻辑。下面是我正在处理的dag文件...

问题是如何将消息从每个任务传递到另一个任务

代码语言:javascript
复制
@dag_factory
def create_dag():
    with DAG(
        dag_id="DSStest",
        default_args=default_args,
        schedule_interval=timedelta(1),
    ) as dag:
        # Define operators here, for example:

        output_file = path_in_workspace("testout")

        rscript_file = path_in_workspace("rtest2.R ")

        bcmd1 = "downloading some file here..."

        t0 = PythonOperator(
            task_id="start",
            python_callable=my_func2,
            provide_context=True,
            op_args=[output_file, 0],
        )

        t1 = PythonOperator(
            task_id="job1",
            python_callable=my_func1,
            provide_context=True,
            op_args=[output_file, 1],
        )

        t2 = PythonOperator(
            task_id="job2",
            python_callable=my_func1,
            provide_context=True,
            op_args=[output_file, 2],
        )

        t10 = PythonOperator(
            task_id="job10",
            python_callable=my_func2,
            provide_context=True,
            op_args=[output_file, 10],
        )

        t20 = BashOperator(
            task_id="job20",
            bash_command=bcmd1,
            queue={
                "worker_type": "png-bash-worker",
                "request_memory": "1G",
                "request_cpu": 1,
            },
        )

        # Define dependencies between operators here, for example:

        t0 >> t1
        t0 >> t2
        t1 >> t10
        t2 >> t10
        t10 >> t11
        t11 >> t20

        return dag  # Do not change this
EN

回答 1

Stack Overflow用户

发布于 2018-08-17 04:25:07

我建议看一下这个例子,它显示/解释了关于xcoms和PythonOperators的所有内容:

example_xcom.py

官方的airflow页面也详细解释了xcoms:

official documentation

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51881118

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档