亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

氣流:如何確保 DAG 每 5 分鐘運行一次?

氣流:如何確保 DAG 每 5 分鐘運行一次?

瀟瀟雨雨 2021-06-20 16:08:16
我正在探索Apache Airflow。我正在使用一種在 MySQL 中插入記錄的方法。我已經安排DAG在每 5 分鐘后運行一次,但它似乎沒有發生,因為 MYSQL 時間戳告訴 MySQL 任務在 5 分鐘內被執行多次。如您所見,它正在幾分鐘內插入記錄。下面是我的代碼:import datetime as dtfrom airflow import DAGfrom airflow.hooks.mysql_hook import MySqlHookfrom airflow.operators.bash_operator import BashOperatorfrom airflow.operators.python_operator import PythonOperatordef fetch_data_mysql():    mysql_hook = MySqlHook(mysql_conn_id='mysql_default')    sql = 'SELECT * from random_table'    sql = "INSERT INTO random_table(text) VALUES ('Hi Adnan')"    print('INSERT MYSQL RESULT')    # results = mysql_hook.get_records(sql)    # results = mysql_hook.run(sql, autocommit=True, parameters=('Hi Addu',))    mysql_hook.run(sql, autocommit=True)def print_world():    print('world')    return 'WORLD IN SEPTEMBER'default_args = {    'owner': 'me',    'start_date': dt.datetime(2018, 9, 11),    'retries': 1,    'retry_delay': dt.timedelta(minutes=2),}with DAG('airflow_tutorial_v01',         default_args=default_args,         schedule_interval='0/5 * * * *',         ) as dag:    print_hello = BashOperator(task_id='print_hello',                               bash_command='echo "hello"')    sleep = BashOperator(task_id='sleep',                         bash_command='sleep 5')    print_world = PythonOperator(task_id='print_world',                                 python_callable=print_world)    mysql_task = PythonOperator(task_id='mysql_tut', python_callable=fetch_data_mysql)print_hello >> sleep >> print_world >> mysql_task我正在使用v1.10.0.日志鏈接在這里:- https://www.dropbox.com/s/f0g64mhi8sgzlvw/my_simple_dag.py.log?dl=0
查看完整描述

2 回答

?
MYYA

TA貢獻1868條經驗 獲得超4個贊

你在回填。如果您檢查日志,其執行日期為2018-09-20 00:15:00+00:00、2018-09-20 00:20:00+00:00、2018-09-20 00:25:00+00:00等。


將以下內容添加到您的default_args:


'catchup_by_default': False


你default_args應該看起來像:


default_args = {

    'owner': 'me',

    'start_date': dt.datetime(2018, 9, 11),

    'retries': 1,

    'retry_delay': dt.timedelta(minutes=2),

    'catchup_by_default': False,

}


查看完整回答
反對 回復 2021-06-22
  • 2 回答
  • 0 關注
  • 220 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號