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

Airflow 在 python operator 下如何使用execution_date变量呢?不复杂,但是要跳出宏变量的圈,不要老想着用下面这种宏实现就行了

thedate = '{{(execution_date - macros.timedelta(days=1)).strftime("%Y-%m-%d")}}'

在 python operator 下,用如下代码

def example(**context):
	execution_date = context['execution_date'] // 这里获取 execution_date 变量
	thedate = execution_date - timedelta(days=1) # 获得前一天的时间

task_example = PythonOperator(
    task_id='clean_adv_user_hs_to_ch',
    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-kwargs

更多架构、PHP、GO、大数据相关踩坑实践技巧请关注我的公众号

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值