简体   繁体   中英

Airflow read the trigger dag dag_run.conf content

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

You can't use Jinja templating as you did.

The {{kwargs["dag_run"].conf["execution_date"]}} will not be rendered.

You can access DAG information via:

dag_run = kwargs.get('dag_run')
task_instance = kwargs.get('task_instance')
execution_date = kwargs.get('execution_date')

Passing variable in Trigger Operator (airflow v2.1.2)

    trigger_dependent_dag = TriggerDagRunOperator(
        task_id="trigger_dependent_dag",
        trigger_dag_id="dependent-dag",
        conf={"test_run_id": "rx100"},
        wait_for_completion=False
    )

Reading it in dependent dag via context['dag_run'].conf['{variable_key}']

def dependent_fuction(**context):
    print("run_id=" + context['dag_run'].conf['test_run_id'])
    print('Dependent DAG has completed.')
    time.sleep(180)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM