【问题标题】:Airflow API - Output of the DAG run available through APIAirflow API - DAG 运行的输出可通过 API 获得
【发布时间】:2020-07-18 09:39:11
【问题描述】:

我正在通过如下 API 触发 DAG 以执行 python 脚本来运行命令。

curl -X POST -H "Cache-Control: no-cache" -H "Content-Type: application/json" http://localhost:8080/api/experimental/dags/DAG-3/dag_runs -d '{"conf":"{\"hostname\":\"<servername>\",\"username\":\"test\", \"password\":\"<password>\", \"command1\":\"uname -a\" }"}'

执行 curl 时我得到如下响应

{"execution_date":"2020-07-17T18:26:58+00:00","message":"Created <DagRun DAG-3 @ 2020-07-17 18:26:58+00:00: manual__2020-07-17T18:26:58+00:00, externally triggered: True>"}

我可以在 DAG 日志中看到脚本执行成功,

[2020-07-17 18:25:03,982] {bash_operator.py:122} INFO - Output:
[2020-07-17 18:25:04,303] {bash_operator.py:126} INFO - Linux servername 3.10.0-693.21.1.el7.x86_64 #1 SMP Fri Feb 23 18:54:16 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[2020-07-17 18:25:04,321] {bash_operator.py:130} INFO - Command exited with return code 0

但是我需要这个输出必须作为 JSON 响应返回,我该如何实现它。 谢谢

【问题讨论】:

    标签: python python-3.x airflow python-jsons


    【解决方案1】:

    Airflow API 是异步的,因为您的 curl 只是启动 DAG 运行 - 它不会等到它完成(因为我们无法知道完成需要多长时间,可能需要几天,或者周)。

    Airflow API 仍在开发中,AFAIK 无法从中检索 DAG 运行的日志

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-08
      • 1970-01-01
      • 2021-04-22
      • 1970-01-01
      • 2022-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多