Make custom Airflow macros expand other macros

后端 未结 3 1665
天涯浪人
天涯浪人 2020-12-03 07:18

Is there any way to make a user-defined macro in Airflow which is itself computed from other macros?

from airflow impo         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 07:34

    user_defined_macros are not processed as templates by default. If you want to keep a template in a user_defined_macro (or if you use a template in a params variable), you can always re-run the templating function manually:

    class DoubleTemplatedBashOperator(BashOperator):
        def pre_execute(self, context):
            context['ti'].render_templates()
    

    And this will work for templates that don't also reference other parameters or UDMs. This way, you can have "two-deep" templates.

    Or put your UDM directly in the BashOperator's command instead (the easiest solution):

    BashOperator(
        task_id='bash_op',
        bash_command='echo "{{ dag.following_schedule(execution_date) }}"',
        dag=dag,
    )
    

提交回复
热议问题