项目目录:本案例基于pycharm项目虚拟环境
1.进入项目虚拟环境目录
yololi@bogon bin % pwd
/Users/yololi/PycharmProjects/pythonProjecttest/venv/bin
2.安装airflow
./python3.8 -m pip install apache-airflow==2.2.5 -i https://pypi.tuna.tsinghua.edu.cn/simple
3.初始化数据库
./airflow db init
初始化数据库后会在本地目录下生成airflow文件夹
4.修改airflow.cfg文件dags_folder执行到自己写的代码目录下
dags_folder = /Users/yololi/PycharmProjects/pythonProjecttest/test
5.编写测试代码
from airflow.decorators import task
from airflow import DAG
from datetime import datetime, timedeltawith DAG('debug_demo2',default_args={'depends_on_past': False, # 是否依赖上一个任务执行完成"retries": 1,"retry_delay": timedelta(minutes=5),'sla': timedelta(minutes=45),},# [END default_args]description='测试demo',schedule_interval='*/5 * * * *',# schedule_interval='0 */2 * * *',start_date=datetime(2023, 3, 1),
) as dag:@task(task_id="debug_test2")def f_task(**context):print("xxxxhhhooo")task1=f_task()
6.编辑脚本运行参数
tasks test :airflow2脚本运行命令
debug_demo2:对应dag_id
debug_test2:对应task_id
2023-11-30:时间参数