Airflow - Get start time of dag run

烂漫一生 提交于 2019-12-24 00:46:07

问题


Is it possible to get the actual start time of a dag in Airflow? By start time I mean the exact time the first task of a dag starts running.

I know I can use macros to get the execution date. If the job is ran using trigger_dag this is what I would call a start time but if the job is ran on a daily schedule then {{ execution_date }} returns yesterdays date.

I have also tried to place datetime.now().isoformat() in the body of the dag code and then pass it to a task but this seems to return the time the task is first called rather than when the dag itself started.


回答1:


{{ dag_run.start_date }} provides the actual start time of the dag




回答2:


I am following the way as you stated:

By start time I mean the exact time the first task of a dag starts running

You can still do this with macros on your first task, try this {{ task.start_date }}

All the variables can be found in TaskInstance class: https://github.com/apache/incubator-airflow/blob/master/airflow/models.py#L746



来源:https://stackoverflow.com/questions/47096829/airflow-get-start-time-of-dag-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!