Ajouter hello_world.py
ajout example basique dag
This commit is contained in:
29
hello_world.py
Normal file
29
hello_world.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from airflow.decorators import dag, task
|
||||
from datetime import datetime
|
||||
|
||||
# 1. On définit le DAG avec le décorateur @dag
|
||||
@dag(
|
||||
dag_id="hello_world_taskflow",
|
||||
start_date=datetime(2026, 1, 1),
|
||||
schedule_interval="@daily", # Se lance tous les jours à minuit
|
||||
catchup=False, # Ne rattrape pas les exécutions passées
|
||||
tags=["exemple"],
|
||||
)
|
||||
def hello_world_dag():
|
||||
|
||||
# 2. On définit une première tâche
|
||||
@task
|
||||
def get_name():
|
||||
return "Collaborateur"
|
||||
|
||||
# 3. On définit une deuxième tâche qui reçoit un paramètre
|
||||
@task
|
||||
def say_hello(name):
|
||||
print(f"Hello {name} ! Bienvenue sur Airflow 2026.")
|
||||
|
||||
# 4. On définit l'ordre d'exécution (le workflow)
|
||||
user_name = get_name()
|
||||
say_hello(user_name)
|
||||
|
||||
# 5. On instancie le DAG
|
||||
hello_world_dag()
|
||||
Reference in New Issue
Block a user