Airflow 读取触发器 dag dag_run.conf 内容 [英] Airflow read the trigger dag dag_run.conf content
本文介绍了Airflow 读取触发器 dag dag_run.conf 内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Airflow 的新手.我想读取用户传递的 Trigger DAG 配置并将其存储为一个变量,该变量可以作为作业参数传递给实际代码.想要访问触发 DAG 时传递的所有参数.
I am new to Airflow.I would like read the Trigger DAG configuration passed by user and store as a variable which can be passed as job argument to the actual code. Would like to access all the parameters passed while triggering the DAG.
def get_execution_date(**kwargs):
if ({{kwargs["dag_run"].conf["execution_date"]}}) is not None:
execution_date = kwargs["dag_run"].conf["execution_date"]
print(f" execution date given by user{execution_date}")
else:
execution_date = str(datetime.today().strftime("%Y-%m-%d"))
return execution_date
推荐答案
您不能像以前那样使用 Jinja 模板.
You can't use Jinja templating as you did.
{{kwargs[dag_run"].conf[execution_date"]}}
不会被渲染.
您可以通过以下方式访问 DAG 信息:
You can access DAG information via:
dag_run = kwargs.get('dag_run')
task_instance = kwargs.get('task_instance')
execution_date = kwargs.get('execution_date')
这篇关于Airflow 读取触发器 dag dag_run.conf 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文