Airflow【实践 01】Airflow官网+自测源代码举例(简化安装+官方及自测python代码)_airflow源码包安装(4)

Airflow官网+自测源代码举例

官方网站地址:
https://airflow.apache.org/docs/apache-airflow/2.7.2/,本文是基于
2.7.2版本进行的说明。

1.准备

1.1 安装

上一篇的 Quick Start 有详细的安装过程,这里做最简安装启动:

# 1.设置安装目录
export AIRFLOW\_HOME=~/airflow

# 2.创建虚拟环境并安装
# 创建并切换到airflow虚拟环境
conda create -n airflow python=3.8
conda activate airflow
pip install "apache-airflow==2.7.2"

# 3.前台启动【在虚拟环境下】
airflow standalone

1.2 查询DAG目录

  1. dags_folder目录将Python文件放置到
[root@tcloud airflow]# cat airflow.cfg | grep dags\_folder
dags_folder = /root/airflow/dags

2.官方

  1. 安装任务所需的依赖【代码执行所需要的依赖】
conda install scikit-learn

  1. 官方举例文件demo.py放置到dags_folder路径下

文件内容如下:

from datetime import datetime

from airflow import DAG
from airflow.decorators import task
from airflow.operators.bash import BashOperator

# A DAG represents a workflow, a collection of tasks
with DAG(dag_id="demo", start_date=datetime(2022, 1, 1), schedule="0 0 \* \* \*") as dag:

    # Tasks are represented as operators
    hello = BashOperator(task_id="hello", bash_command="echo hello")

    @task()
    def airflow():
        print("airflow")

    # Set dependencies between tasks
    hello >> airflow()

  1. 刷新页面即可看到DAG,点击即可执行,效果如下:

demo.jpg

3.自测

  1. 创建测试文件airflow_test.py并放置到dags_folder目录下

文件内容如下:

from datetime import timedelta
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.utils.dates import days_ago

# DAG属性定义
default_args = {
    'owner': 'airFlowTest',
    'depends\_on\_past': False,
    'start\_date': days_ago(31),
    # 填入邮箱,方便失败、重试时发送邮件
    'email': ['xxxxx@qq.com'],
    # 失败时发邮件告警
    'email\_on\_failure': True,
    'email\_on\_retry': False,
    # 重试次数
    'retries': 1,
    'retry\_delay': timedelta(minutes=2),
    # 'queue': 'bash\_queue',
    # 'pool': 'backfill',
    # 'priority\_weight': 10,
    # 'end\_date': datetime(2016, 1, 1),bu
    # 'wait\_for\_downstream': False,
    # 'dag': dag,
    # 'sla': timedelta(hours=2),
    # 'execution\_timeout': timedelta(seconds=300),
    # 'on\_failure\_callback': some\_function,
    # 'on\_success\_callback': some\_other\_function,
    # 'on\_retry\_callback': another\_function,
    # 'sla\_miss\_callback': yet\_another\_function,
    'trigger\_rule': 'all\_success'
}

# 定义dag
dag = DAG(
    'air\_test',
    default\_args=default_args,
    description='A simple airflow test',
    schedule\_interval=timedelta(days=1),
)

step_one = BashOperator(
    task\_id='step\_one',
**先自我介绍一下,小编浙江大学毕业,去过华为、字节跳动等大厂,目前阿里P7**

**深知大多数程序员,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**

**因此收集整理了一份《2024年最新网络安全全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友。**
![img](https://img-blog.csdnimg.cn/img_convert/b1a7082d53148ab867e7c3463c22c679.png)
![img](https://img-blog.csdnimg.cn/img_convert/d5bfa3eb06a3437d6c2723200e911788.png)
![img](https://img-blog.csdnimg.cn/img_convert/fd6bb9e084b754c90435e8e431230d6f.png)
![img](https://img-blog.csdnimg.cn/img_convert/c77b1f7f98c81f76ff4eac9e2d699b94.png)
![img](https://img-blog.csdnimg.cn/img_convert/32cab5a335dc98f85364c768162e202f.png)
![img](https://img-blog.csdnimg.cn/img_convert/ce4ae3d0d383c74165ac0910e29d22ce.png)

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上网络安全知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以点击这里获取](https://bbs.csdn.net/topics/618540462)**
升的进阶课程,涵盖了95%以上网络安全知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[需要这份系统化资料的朋友,可以点击这里获取](https://bbs.csdn.net/topics/618540462)**
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值