如何测试使用XCom的Apache Airflow任务 [英] How to test Apache Airflow tasks that uses XCom

查看:157
本文介绍了如何测试使用XCom的Apache Airflow任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种测试DAG的方法,其中有几个任务需要使用XCom进行通信。

I'm trying to figure out a way to test a DAG where I have a couple of tasks communicating using XCom.

由于console命令只允许我执行以下操作:从DAG运行任务,有没有一种方法可以测试通讯而不必通过UI运行DAG?

Since the console command only allow me to run tasks from a DAG, is there a way to test the communication without having to run the DAG via the UI?

谢谢

推荐答案

这是对我有用的方法。

即使Airflow网页上指出测试命令确实可以不会生成或保持任何状态,请按顺序运行airflow test命令。

Even though the Airflow web page states that the test command does not generate or keeps any state, running the airflow test command in sequence worked.

基本上,您会这样做:

Airflow test my_dag task1 date
Airflow test my_dag task2 date

其中task1返回值或使用xcom_push方法发送值,然后task2运行xcom_pull获取值并继续操作。

where task1 returns the value or uses xcom_push method to send the value and then task2 run xcom_pull to get the value and move on.

它为我工作。如果您有其他方法或其他问题,请发表评论。

It worked for me. Please comment if you have different approaches or other questions.

这篇关于如何测试使用XCom的Apache Airflow任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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