init: airflow_demo 初始化示例 DAG 集合

This commit is contained in:
2026-10-13 14:14:04 +08:00
commit 69a1df7aa0
12 changed files with 1112 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
from datetime import datetime, timedelta
from airflow import DAG
from airflow.operators.python import PythonOperator
from airflow.operators.bash import BashOperator
# 默认参数定义
default_args = {
'owner': 'xiaozhang',
'depends_on_past': False,
'email_on_failure': False,
"on_failure_callback":xx,
'retries': 1,
'retry_delay': timedelta(minutes=5),
}
# dag = DAG(
# dag_id='hello_world',
# default_args=default_args,
# start_date=datetime(2023, 1, 1),
# schedule_interval='@daily',
# catchup=False,
# tags= ["demo"]
# )
# 定义任务
def print_hello():
print("Hello, World!")
# 实例化DAG
with DAG(
dag_id='hello_world',
default_args=default_args,
description="这个是一个样例",
start_date=datetime(2024, 10, 1),
schedule_interval='@daily',
catchup=True,
tags= ["demo","xiaozhang"]
) as dag:
task1 = PythonOperator(
task_id='print_hello',
python_callable=print_hello
)
task2 = BashOperator(
task_id='run_bash_command',
bash_command='echo "This is a Bash command"',
)
# 定义依赖关系
task1 >> task2 # task2将在task1完成后执行
# task1.set_downstream(task2) # 这种写法也可以,但是不太推荐,因为不够直观