Airflow 如何在HttpSensor操作符中提取xCom

Airflow 如何在HttpSensor操作符中提取xCom,airflow,apache-airflow-xcom,Airflow,Apache Airflow Xcom,我想调用一个API,它需要我保存在xCom中的上一个任务的数据。如何访问那个xCom 我正在使用HttpOperater和HttpSensor来调用API。您需要在上下文中使用xcom\u pull方法: http_task = SimpleHttpOperator( task_id='http_call', endpoint='nodes/url', data="name=Joe", headers={"Content-Type": "application/x

我想调用一个API,它需要我保存在xCom中的上一个任务的数据。如何访问那个xCom


我正在使用HttpOperater和HttpSensor来调用API。

您需要在上下文中使用xcom\u pull方法:

http_task = SimpleHttpOperator(
    task_id='http_call',
    endpoint='nodes/url',
    data="name=Joe",
    headers={"Content-Type": "application/x-www-form-urlencoded"},
    dag=dag,
)

def get_http_payload(**context):
    http_payload = ['ti'].xcom_pull(task_ids='http_call')
    print(http_payload)

process_output = PythonOperator(
    task_id='process_stuff',
    python_callable=get_http_payload,
    provide_context=True,
    dag=dag,
)

http_task >> process_output
可以使用具有两个模板参数的模板

例如:

HttpSensor(task_id='sfcase_hook_sensor',
                http_conn_id='conn_id', 
                method="GET",
                endpoint= + "xyz.com/abc/{{ti.xcom_pull(task_ids='previous_task_id')}}",
                request_params={
                   "someParam" : "{{ti.xcom_pull(task_ids='previous_task_id')}}"
                },
                extra_options={
                    'verify': False
                },
                headers={
                    "access_token" : token
                },
                response_check=hook_check, xcom_push=True)