首页 > 解决方案 > 如何从以前的运行中提取 xcom 变量

问题描述

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

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

F

我正在查看宏文档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

解决方案


您应该能够使用之前的 task_instanceprevious_ti()

然后你可以使用get_state()它来获取它的状态,并基于它执行操作。


推荐阅读