Airflow 气流:将前一个星期二从执行日期传递给操作员

Airflow 气流:将前一个星期二从执行日期传递给操作员,airflow,Airflow,我有一个dag,每周星期天运行。有一个任务,bash操作符,设置如下: t = BashOperator( task_id='print_date', bash_command="echo Previous Tuesday is: " def get_latest_build_date(dt): bd = dt + relativedelta(weekday=TU(-1)) return bd.strftime('%Y%m%d') 如何将当前执行日期传递给get\u

我有一个dag,每周星期天运行。有一个任务,
bash操作符
,设置如下:

t = BashOperator(
   task_id='print_date',
   bash_command="echo Previous Tuesday is: "

def get_latest_build_date(dt):
   bd = dt + relativedelta(weekday=TU(-1))
   return bd.strftime('%Y%m%d')
如何将当前执行日期传递给
get\u latest\u build\u date
函数

bash_command=“echo上周二是:{{get_latest_build_date(ds)}}

无法使用jinja模板。

使用
DAG的
用户定义的宏

def get_latest_build_date(dt):
   bd = dt + relativedelta(weekday=TU(-1))
   return bd.strftime('%Y%m%d')

with DAG('name',
         ...,
         user_defined_macros={'prior_tues': get_latest_build_date},) as dag:

  t = BashOperator(
     task_id='print_date',
     bash_command="echo Previous Tuesday is: {{ prior_tues(execution_date) }}"