【问题标题】:Pass parameters to Airflow Experimental REST api when creating dag run创建 dag 运行时将参数传递给 Airflow Experimental REST api
【发布时间】:2021-10-08 14:33:14
【问题描述】:

看起来 Airflow 有一个实验性的 REST api,允许用户使用 https POST 请求创建 dag 运行。这太棒了。

有没有办法通过 HTTP 将参数传递给 create dag 运行?从官方文档来看,找到here,答案似乎是“不”,但我希望我错了。

【问题讨论】:

    标签: airflow


    【解决方案1】:

    我遇到了同样的问题。 “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\"}"}'
    

    【讨论】:

    • 拯救了我的一天 :)
    • 我仍然无法理解。对于未来的读者,这并不意味着您只有一个常规的 json 字典作为有效负载。您必须有一个 json 字典,其中包含一个键“conf”和一个必须是有效 json 的 string 值。 IE json-in-json。在我自己的(python)代码中,这意味着这样的事情:payload = dict(conf=json.dumps(dict(key="value"))requests.post(url, json=payload, headers=headers)
    【解决方案2】:

    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\"}"}'
    

    【讨论】:

      【解决方案3】:

      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 的热门搜索结果。

      【讨论】:

        猜你喜欢
        • 2018-05-01
        • 1970-01-01
        • 2016-10-28
        • 2021-10-15
        • 2021-05-08
        • 2022-07-08
        • 2017-06-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多