我们如何使用airflow
中显示在下方链接中的默认变量
https://airflow.apache.org/code.html#default-variables
我在我的代码中使用了这个,如下所示:
def decide_which_task():
if {{ dag_run.task_id }} is "Move_file":
return "move_file"
else:
return "push_to_db"
但我在日志文件中收到错误
NameError:未定义全局名称'dag_run'
答案 0 :(得分:2)
您尝试使用的注释是Jinja在字符串中模板化的注释。
要在任务中使用相同的变量,您需要:
provide_context=True
PythonOperator
def decide_which_task(**context):
mytask = context['task_id']
代码:
def decide_which_task(**context):
if context['task_id'] is "Move_file":
return "move_file"
else:
return "push_to_db"