2
votes

How pull xcom variable from previous run in airflow? Is it possible?

I want to use value from same task_id in previous run_id as jinja variable for data argument in SimpeHttpOperator.

f

I'm looking in macros docs https://airflow.apache.org/docs/stable/macros.html and cant't find any documented way to do this.

UPD Example:

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
)

where REQUESTED_EXPIRED_FLIGHTS is:

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

1 Answers

1
votes

You should be able to access the previous task_instance using previous_ti()

Then you can use get_state() to get its state, and perform actions based on that.