我可以在PythonOperator中使用宏嗎?我試着跟着,但我無法得到渲染的宏!Airflow Python運算符中的宏
dag = DAG(
'temp',
default_args=default_args,
description='temp dag',
schedule_interval=timedelta(days=1))
def temp_def(a, b, **kwargs):
print '{{ds}}'
print '{{execution_date}}'
print 'a=%s, b=%s, kwargs=%s' % (str(a), str(b), str(kwargs))
ds = '{{ ds }}'
mm = '{{ execution_date }}'
t1 = PythonOperator(
task_id='temp_task',
python_callable=temp_def,
op_args=[mm , ds],
provide_context=False,
dag=dag)
我們可以標記這是正確的答案嗎?因爲它是正確的答案 –
爲了向後兼容,你可以像這樣'template_fields':'template_fields = PythonOperator.template_fields +('op_args',)''。順便說一句,我打開了一個[JIRA來添加'op_args'和'op_kwargs'到'PythonOperator'模板字段](https://issues.apache.org/jira/browse/AIRFLOW-1814) –