【发布时间】:2021-10-08 14:33:14
【问题描述】:
看起来 Airflow 有一个实验性的 REST api,允许用户使用 https POST 请求创建 dag 运行。这太棒了。
有没有办法通过 HTTP 将参数传递给 create dag 运行?从官方文档来看,找到here,答案似乎是“不”,但我希望我错了。
【问题讨论】:
标签: airflow
看起来 Airflow 有一个实验性的 REST api,允许用户使用 https POST 请求创建 dag 运行。这太棒了。
有没有办法通过 HTTP 将参数传递给 create dag 运行?从官方文档来看,找到here,答案似乎是“不”,但我希望我错了。
【问题讨论】:
标签: airflow
我遇到了同样的问题。 “conf”值必须在字符串中
curl -X POST \
http://localhost:8080/api/experimental/dags/<DAG_ID>/dag_runs \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '{"conf":"{\"key\":\"value\"}"}'
【讨论】:
payload = dict(conf=json.dumps(dict(key="value"))requests.post(url, json=payload, headers=headers)
从source code 来看,似乎参数可以 被传递到dag 运行中。
如果 http 请求的正文包含 json,并且该 json 包含顶级键 conf,则 conf 键的值将作为配置传递给 trigger_dag。有关其工作原理的更多信息,请访问here。
注意conf键的值必须是字符串,例如
curl -X POST \
http://localhost:8080/api/experimental/dags/<DAG_ID>/dag_runs \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-d '{"conf":"{\"key\":\"value\"}"}'
【讨论】:
stable REST API 不再适用。
你可以做类似的事情 -
curl --location --request POST 'localhost:8080/api/v1/dags/unpublished/dagRuns' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--data-raw '{
"dag_run_id": "dag_run_1",
"conf": {
"key": "value"
}
}'
我知道这个问题是针对实验性 API 提出的,但这个问题是气流 REST API 的热门搜索结果。
【讨论】: