Python 中的 Apache Airflow 入门
Mike Metzger
Data Engineer
@dag(
dag_id="Example_Dag"
)
def example_dag():
@task
def task1():
return "The result from task1"
task1()
example_dag()
from airflow.sdk import task@task def printme(): print("This goes in the logs!")printme()
@task def printme(name: str): print(f"Hi {name} - This goes in the logs!")printme(name='DataCamp')# 日志将增加: # Hi DataCamp - This goes in the logs! # 位于 Airflow 日志中
@task.bash
def bash_example():
return "echo 'Example!'"
bash_example()
@task.bash
def run_cleanup():
return "runcleanup.sh"
run_cleanup()

>> 和 <<
task1() >> task2()# task1 完成后才开始 task2task1() >> task2() >> task3()# task1 完成于 task2 之前,task2 完成于 task3 之前task1() >> task3() task2() >> task3()# task1 与 task2 可并行,但均需完成后才运行 task3
# 下载销售数据后再对账
download_sales_data() >> reconcile()
# 下载库存数据后再对账
download_inventory_data() >> reconcile()
Python 中的 Apache Airflow 入门