Airflow 在 python operator 下如何使用execution_date变量

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、大数据相关踩坑实践技巧请关注个人公众号 大数据

相关文章
相关标签/搜索