Pengantar Apache Airflow dengan 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')# Menambahkan: # Hi DataCamp - This goes in the logs! # ke log Airflow
@task.bash
def bash_example():
return "echo 'Example!'"
bash_example()
@task.bash
def run_cleanup():
return "runcleanup.sh"
run_cleanup()

>> dan <<
task1() >> task2()# task1 selesai sebelum task2 mulaitask1() >> task2() >> task3()# task1 selesai sebelum task2 dan task2 selesai sebelum task3task1() >> task3() task2() >> task3()# task1 dan task2 bisa berjalan bersamaan tapi keduanya harus selesai sebelum task3
# Unduh data penjualan sebelum rekonsiliasi
download_sales_data() >> reconcile()
# Unduh data inventaris sebelum rekonsiliasi
download_inventory_data() >> reconcile()
Pengantar Apache Airflow dengan Python