通过CLI访问传递给Airflow的配置参数

编程入门 行业动态 更新时间:2024-10-24 04:34:20
本文介绍了通过CLI访问传递给Airflow的配置参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图在触发dag运行时将以下配置参数传递给Airflow CLI。以下是我正在使用的trigger_dag命令。

I am trying to pass the following configuration parameters to Airflow CLI while triggering a dag run. Following is the trigger_dag command I am using.

airflow trigger_dag -c '{"account_list":"[1,2,3,4,5]", "start_date":"2016-04-25"}' insights_assembly_9900

我的问题是,如何在dag运行中访问在运算符内部传递的con参数。

My problem is that how can I access the con parameters passed inside an operator in the dag run.

推荐答案

这可能是一个延续 devj 提供的答案。

This is probably a continuation of the answer provided by devj.

  • 在 airflow.cfg 处,以下属性应设置为true : dag_run_conf_overrides_params = True

  • At airflow.cfg the following property should be set to true: dag_run_conf_overrides_params=True

    在定义PythonOperator时,传递以下参数 provide_context = True 。例如:

    While defining the PythonOperator, pass the following argument provide_context=True. For example:

    get_row_count_operator = PythonOperator(task_id='get_row_count', python_callable=do_work, dag=dag, provide_context=True)

  • 定义python可调用对象(请注意 ** kwargs )的使用:
  • Define the python callable (Note the use of **kwargs):
  • def do_work(**kwargs): table_name = kwargs['dag_run'].conf.get('table_name') # Rest of the code

  • 从命令行调用dag:
  • airflow trigger_dag read_hive --conf '{"table_name":"my_table_name"}'

    我有发现此讨论对您有所帮助。

    I have found this discussion to be helpful.

    更多推荐

    通过CLI访问传递给Airflow的配置参数

    本文发布于:2023-11-23 19:42:30,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1622654.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:参数   CLI   Airflow

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!