Home > Software design >  The datetime in airflow Task instance keeps on updating itself
The datetime in airflow Task instance keeps on updating itself

Time:11-20

I created a trigger_date_time from a datetime object like this

trigger_date_time = str(datetime.now(tz=timezone.utc)).replace(' ', '_')

I use this variable in my airflow DAG definition. I noticed that its value keeps on updating as the task instance is being executed. I cannot comprehend how it works and how to solve this issue. I simply want to have a trigger_date_time holding the value when I trigger the DAG execution throughout the execution.

CodePudding user response:

Airflow is parsing the dag every 30 sec (by default) and thats why datetime always returns a value to your trigger_date_time variable. to get the execution date you need to get the value from the dag_run itself.

you didn't share the full code, so its hard to understand the context here, but if you are in the dag it self you can use Jinja template, for example {{ ts }}.

if you are inside a PythonOperator then you can use context['execution_date']

  • Related