如何用 pycharm 調試 airflow


airflow 和 pycharm 相關基礎知識請看其他博客

 

我們在使用 airflow的 dag時。 每次寫完不知道對不對的,總不能到頁面環境中跑一下,等到報錯再調試吧。這是很讓人惱火的事情

這里我想分享  如何用 pycharm 對 airflow 進行調試

 

airflow的運行環境,依賴於  airflow.cfg和  airflow_home,

pycharm 的項目目錄應該和 airflow_home 相同目錄。

 

1.  airflow的配置 

詳細配置看請看其他博客,這里只是表名我的  airflow_home   = /data/airflow

[core]

dags_folder = /data/airflow/dags

# The folder where airflow should store its log files
# This path must be absolute
base_log_folder = /data/airflow/logs

plugins_folder = /data/airflow/plugins

sql_alchemy_conn =  mysql://airflow:airflow@IP:3306/airflowtest

broker_url = sqla+mysql://airflow:airflow@IP:3306/airflowtest

 

2. 啟動webserver 模式下airflow

airflow webserver -D

airflow  scheduler -D 

airflow  workder -D 

 

 

3. 在/data/airflow/dags 下新建范例  dag

 vim hello_world.py 

from datetime import datetime
from airflow import DAG
from airflow.operators.dummy_operator import DummyOperator
from airflow.operators.python_operator import PythonOperator


def print_hello():
     print ('hello my name is fanglianchao')
     return 'Hello world!'


dag = DAG('hello_world', description='Simple tutorial DAG',
          schedule_interval='0 12 * * *',
          start_date=datetime(2017, 3, 20), catchup=False)

dummy_operator = DummyOperator(task_id='dummy_task', retries=3, dag=dag)

hello_operator = PythonOperator(task_id='hello_task', python_callable=print_hello, dag=dag)

dummy_operator >> hello_operator
~                                

4.執行測試:

如果以下測試成功,就代表安裝成功了, 可以到 web 里面  觸發執行看看

 airflow test hello_world hello_task 2019-10-10

 

 

 

 

 

5. pycharm 項目配置

 

 執行這個dag 

 

 編輯這個dag 配置文件

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM