Warm tip: This article is reproduced from serverfault.com, please click

testing-使用 Airflow 测试与DebugExecutor调试 Airflow 任务

(testing - Debugging airflow tasks using airflow test vs using DebugExecutor)

发布于 2020-11-29 10:46:50

我正在寻找在IDE中运行/调试任务和dag的最佳方法。我看到有两种方法可以做到这一点。我可以airflow test在调试模式下为特定的dag和可选的任务运行命令。其他方法是使用DebugExecutor和运行特定的dag。我看到这两种方式都要求Airflow数据库已启动并正在运行,并且所有池都已配置(可能还有队列)。我的问题是:

  1. 两者的主要区别是什么?
  2. 是否在引擎盖下airflow test使用DebugExecutor
  3. 有没有一种方法可以在不运行Airflow数据库和创建依赖池和队列的情况下运行/调试dag和任务?
Questioner
partlov
Viewed
11
12.9k 2020-11-29 19:50:53

两者的主要区别是什么?

Debug Executor运行完整的DAG Run,因此你可以测试触发规则。 airflow test该命令仅运行一项任务。

在Airflow 2.0中,这一点更加清晰。我们有单独的命令:

  • airflow dags test-使用开始一个DAG Run DebugExecutor
  • airflow tasks test -开始一项任务。

DebugExecutor引擎盖下是否进行 Airflow 测试

否。如果使用,DebugExecutor则需要运行完整的调度程序。如果使用该airflow task命令,则仅执行工作者正在执行的代码。

有没有一种方法可以在不运行Airflow数据库和创建依赖池和队列的情况下运行/调试dag和任务?

你可以使用加载DAG,DagBag然后调用任务的execute方法。

from airflow.model.dagbag import DagBag
dag_file_path = "/home/test-user/dags/dag-file.py"
dagbag = DagBag(dag_folder=dag_file_path)
dagbag.dags['test-dag-id'].task_dict['task-id'].execute({})