使用 Airflow 构建数据流水线
Volker Janz
Senior Developer Advocate at Astronomer
$$
$$

$$
| Operator | 用例 |
|---|---|
ApprovalOperator |
二选一:批准/拒绝 |
HITLBranchOperator |
选择接下来运行的任务 |
HITLOperator |
自定义选项 + 表单 |
HITLEntryOperator |
纯表单输入,无选项 |
$$
from airflow.providers.standard.operators.hitl import HITLEntryOperator from airflow.sdk import Paramreview = HITLEntryOperator( task_id="human_review", subject="Review AI draft response", body="{{ ti.xcom_pull(task_ids='generate_draft') }}", params={ "feedback": Param("", type="string"), "urgency": Param("p3", type="string"), }, )
@task def send_response(hitl_output): feedback = hitl_output["params_input"]["feedback"] urgency = hitl_output["params_input"]["urgency"] print(f"Sending response (urgency: {urgency}): {feedback}")draft = generate_draft() chain(draft, review) send_response(review.output)
params_inputchosen_optionsfrom airflow.providers.standard.operators.hitl import HITLBranchOperatorroute = HITLBranchOperator( task_id="route_complaint", subject="Route customer complaint", body="A customer reported an issue. Choose the responsible team.", options=["Billing Issue", "General Inquiry", "Technical Issue"], options_mapping={ "Billing Issue": "handle_billing", "Technical Issue": "handle_technical", "General Inquiry": "handle_general", }, defaults=["General Inquiry"], )

使用 Airflow 构建数据流水线