execution_date in airflow: need to access as a variable

后端 未结 6 871
无人共我
无人共我 2020-12-04 14:19

I am really a newbie in this forum. But I have been playing with airflow, for sometime, for our company. Sorry if this question sounds really dumb.

I am writing a p

6条回答
  •  有刺的猬
    2020-12-04 14:43

    The PythonOperator constructor takes a 'provide_context' parameter (see https://pythonhosted.org/airflow/code.html). If it's True, then it passes a number of parameters into the python_callable via kwargs. kwargs['execution_date'] is what you want, I believe.

    Something like this:

    def python_method(ds, **kwargs):
        Variable.set('execution_date', kwargs['execution_date'])
        return
    
    doit = PythonOperator(
        task_id='doit',
        provide_context=True,
        python_callable=python_method,
        dag=dag)
    

    I'm not sure how to do it with the BashOperator, but you might start with this issue: https://github.com/airbnb/airflow/issues/775

提交回复
热议问题