【问题标题】:Passing variable in airflow macros在气流宏中传递变量
【发布时间】:2021-06-06 07:11:39
【问题描述】:

请帮帮我 {{ execution_date.subtract(hours = 5) }} 在这里,我想将它作为变量传递,而不是硬编码 5。 我无法找到传递变量并最终使用变量值的方法。

【问题讨论】:

    标签: python variables macros airflow


    【解决方案1】:

    你可以使用:

    f'echo {{{{ execution_date.subtract(hours = {value}) }}}}'
    

    使用 BashOperator 的示例:

    value = 5 # This can be set dynamically
    hello_my_task = BashOperator(
        task_id='my_task',
        bash_command=f'echo {{{{ execution_date.subtract(hours = {value}) }}}}',
        dag=dag,
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-13
      • 2023-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-08
      相关资源
      最近更新 更多