How to pull xcom value from other task instance in the same DAG run (not the most recent one)?

ぃ、小莉子 提交于 2019-11-29 17:37:38

This asnwers your question [How to pull xcom value from other task instance in the same DAG run (not the most recent one)? ]
See the example below :

t1 = SomeOperator(
        task_id='Your_t1_Task_ID',
        ...
        ...
        dag=dag)

    def get_records(**kwargs):
        ti = kwargs['ti']
        xcom = ti.xcom_pull(task_ids='Your_t1_Task_ID')
        string_to_print = 'Value in xcom is: {}'.format(xcom)
        #string_to_print holds that value, you can also print it in the logs
        logging.info(string_to_print)

    t2 = PythonOperator(
        task_id='records',
        provide_context=True,
        python_callable=get_records,
        dag=dag)

    t1 >> t2
  • I think you are looking for include_prior_dates param of xcom_pull() method
  • Do note that it will return entire history of Xcoms (python list, each item being one xcom record) pushed by the given task (filtered by task_id(s)) and then you will have to manually filter-out the desired xcom using execution_date field
  • It maybe difficult to supply exact execution_date for filtering; for that, see how they've implemented execution_delta and execution_date_fn params in ExternalTaskSensor
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!