0

我正在通过如下 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 响应返回,我该如何实现它。谢谢

4

1 回答 1

1

The Airflow API is asynchronous in that your curl simply starts a DAG run - it doesn't wait till it's complete (Because we have no way of knowing how long it will take to complete, it could be days, or weeks).

The Airflow API is still under development and AFAIK there is no way to retrieve the logs of a DAG run from it

于 2020-07-18T09:44:12.193 回答