Giới thiệu về Apache Airflow bằng Python
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')# Thêm vào log: # Hi DataCamp - This goes in the logs! # trong Airflow
@task.bash
def bash_example():
return "echo 'Example!'"
bash_example()
@task.bash
def run_cleanup():
return "runcleanup.sh"
run_cleanup()

>> và <<
task1() >> task2()# task1 hoàn tất trước khi task2 bắt đầutask1() >> task2() >> task3()# task1 xong trước task2 và task2 xong trước task3task1() >> task3() task2() >> task3()# task1 và task2 có thể chạy song song nhưng cả hai phải xong trước task3
# Tải dữ liệu bán hàng trước khi đối soát
download_sales_data() >> reconcile()
# Tải dữ liệu tồn kho trước khi đối soát
download_inventory_data() >> reconcile()
Giới thiệu về Apache Airflow bằng Python