Airflow 在 python operator 下如何使用execution_date變量呢?不復雜,可是要跳出宏變量的圈,不要老想着用下面這種宏實現就好了html
thedate = '{{(execution_date - macros.timedelta(days=1)).strftime("%Y-%m-%d")}}'
在 python operator 下,用以下代碼python
def example(**context): execution_date = context['execution_date'] // 這裏獲取 execution_date 變量 thedate = execution_date - timedelta(days=1) # 得到前一天的時間 task_example = PythonOperator( task_id='task_example_id', provide_context=True, // 這裏要設置爲 True python_callable=example, dag=dag, )
參考架構
https://airflow.readthedocs.io/en/stable/howto/operator/python.html https://stackoverflow.com/questions/50093718/airflow-python-script-with-execution-date-in-op-kwargside
更多架構、PHP、GO、大數據相關踩坑實踐技巧請關注個人公衆號 大數據