【问题标题】:How pull xcom variable from previous run如何从以前的运行中提取 xcom 变量
【发布时间】:2020-02-01 20:37:01
【问题描述】:

如何从先前运行的气流中提取 xcom 变量?有可能吗?

我想使用之前 run_id 中相同 task_id 的值作为 SimpeHttpOperator 中 data 参数的 jinja 变量。

我正在查看宏文档https://airflow.apache.org/docs/stable/macros.html 并且找不到任何记录在案的方法。

UPD 示例:

select_expired = SimpleHttpOperator(
    task_id='select_expired',
    http_conn_id='clickhouse_http',
    endpoint='/',
    method='POST',
    data=REQUESTED_EXPIRED_FLIGHTS,
    xcom_push=True,
    pool='clickhouse_select',
    dag=dag
)

REQUESTED_EXPIRED_FLIGHTS 是:

insert into table where column = '{{ ??????? (value returned in previous task) }}'

【问题讨论】:

    标签: airflow


    【解决方案1】:

    你应该可以使用previous_ti()访问之前的task_instance

    然后您可以使用get_state() 获取其状态,并根据该状态执行操作。

    【讨论】:

    • 您能否为答案中的更新示例提供更多解释?
    • 嗨,爱德华,抱歉耽搁了,我可以。您能否提供更大的代码 sn-p 供我帮助?
    猜你喜欢
    • 2021-10-11
    • 1970-01-01
    • 1970-01-01
    • 2020-01-16
    • 2023-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-30
    相关资源
    最近更新 更多