我正在探索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,
}
添加回答
舉報
0/150
提交
取消