airflow零基础入门
生活随笔
收集整理的這篇文章主要介紹了
airflow零基础入门
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Airflow 入門
簡介
Airflow是什么
Airflow是airbnb開發的一個任務調度平臺,目前已經加入apache基金會
Airflow有什么用
Airflow是一個可編程,調度和監控的工作流平臺。基于有向無環圖(DAG),airflow可以定義一組有依賴的任務,按照依賴依次執行。 airflow不僅提供了豐富的命令行工具用于系統管控,還提供了一套web管理界面用于方便地管控調度任務,并且對任務運行狀態進行實時監控,方便了系統的運維和管理。
因此,如果有一系列的任務需要調度,同時,各任務之間還有著依賴關系,那么可以考慮使用airflow。
與Airflow同類型的產品
有興趣的同學可以閱讀以下鏈接Workflow Processing Engine Overview 2018 英文版
2018工作流引擎比較 中文版
Airflow official Tutorial
official tutorial
""" Code that goes along with the Airflow tutorial located at: https://github.com/apache/airflow/blob/master/airflow/example_dags/tutorial.py """ from airflow import DAG # 需要使用DAG實例化一個DAG的對象,因此,DAG是必須的 from airflow.operators.bash_operator import BashOperator from datetime import datetime, timedelta""" default_args是一個詞典,之后會將此詞典傳入DAG的構造函數中. DAG中的task在構造時將會這些值來初始化。 這種設計是將一些公共的配置提出來, 尤其是一些實例化task必備的參數,例如'owner'等。 更多可用的參數請參考 https://airflow.apache.org/code.html#airflow.models.BaseOperator """" default_args = {'owner': 'airflow','depends_on_past': False,'start_date': datetime(2015, 6, 1),'email': ['airflow@example.com'],'email_on_failure': False,'email_on_retry': False,'retries': 1,'retry_delay': timedelta(minutes=5),# 'queue': 'bash_queue',# 'pool': 'backfill',# 'priority_weight': 10,# 'end_date': datetime(2016, 1, 1), }""" 實例化一個DAG對象,實例化DAG時必須傳入一個獨一無二的tag_id,然后將之前定義好的默認參數傳入,同時,也傳入了schedule_interval """ dag = DAG('tutorial', default_args=default_args, schedule_interval=timedelta(days=1))# t1, t2 and t3 are examples of tasks created by instantiating operators """ task 是BashOperator的實例 task_id同來標致task bash_command 是執行的命令 dag為之前實例化的DAG對象 """ t1 = BashOperator(task_id='print_date',bash_command='date',dag=dag)t2 = BashOperator(task_id='sleep',bash_command='sleep 5',retries=3, # 可以重寫默認的參數dag=dag)# Jinja模板 templated_command = """{% for i in range(5) %}echo "{{ ds }}" # 變量echo "{{ macros.ds_add(ds, 7)}}" #函數echo "{{ params.my_param }}" # 詞典{% endfor %} """t3 = BashOperator(task_id='templated',bash_command=templated_command, params={'my_param': 'Parameter I passed in'},dag=dag)t2.set_upstream(t1) t3.set_upstream(t1) # 等價于 t1 >> [t2, t3] 復制代碼Airflow 實踐
Airflow安裝
install
pip install apache-airflow
如果出現安裝失敗或者初始化db失敗,可以看下是否是因為某個包安裝失敗或者版本不匹配,然后針對性地安裝相關包即可
轉載于:https://juejin.im/post/5c9618b8f265da60f16323b4
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的airflow零基础入门的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于自己写博客的重要性
- 下一篇: 泛在电力物联网分析—架构形式