[AIRFLOW-815] Add prev/next execution dates to template variables This patch adds the previous/next execution dates to the default variables available in a template.
Closes #2033 from danielvdende/add-execution-dates Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/a67e4390 Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/a67e4390 Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/a67e4390 Branch: refs/heads/v1-8-test Commit: a67e4390d2217dd0fdc3429e943cdc6c552fac73 Parents: 3ca287d Author: Daniel van der Ende <daniel.vandere...@gmail.com> Authored: Sun Jan 29 12:41:36 2017 +0100 Committer: Bolke de Bruin <bo...@xs4all.nl> Committed: Sun Jan 29 12:41:39 2017 +0100 ---------------------------------------------------------------------- airflow/models.py | 5 +++++ docs/code.rst | 2 ++ 2 files changed, 7 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/a67e4390/airflow/models.py ---------------------------------------------------------------------- diff --git a/airflow/models.py b/airflow/models.py index b9015eb..b9af58e 100755 --- a/airflow/models.py +++ b/airflow/models.py @@ -1474,6 +1474,9 @@ class TaskInstance(Base): yesterday_ds = (self.execution_date - timedelta(1)).isoformat()[:10] tomorrow_ds = (self.execution_date + timedelta(1)).isoformat()[:10] + prev_execution_date = task.dag.previous_schedule(self.execution_date) + next_execution_date = task.dag.following_schedule(self.execution_date) + ds_nodash = ds.replace('-', '') ts_nodash = ts.replace('-', '').replace(':', '') yesterday_ds_nodash = yesterday_ds.replace('-', '') @@ -1543,6 +1546,8 @@ class TaskInstance(Base): 'dag_run': dag_run, 'run_id': run_id, 'execution_date': self.execution_date, + 'prev_execution_date': prev_execution_date, + 'next_execution_date': next_execution_date, 'latest_date': ds, 'macros': macros, 'params': params, http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/a67e4390/docs/code.rst ---------------------------------------------------------------------- diff --git a/docs/code.rst b/docs/code.rst index 0e1993e..fabe6db 100644 --- a/docs/code.rst +++ b/docs/code.rst @@ -127,6 +127,8 @@ Variable Description ``{{ ts }}`` same as ``execution_date.isoformat()`` ``{{ ts_nodash }}`` same as ``ts`` without ``-`` and ``:`` ``{{ execution_date }}`` the execution_date, (datetime.datetime) +``{{ prev_execution_date }}`` the previous execution date (if available) (datetime.datetime) +``{{ next_execution_date }}`` the next execution date (datetime.datetime) ``{{ dag }}`` the DAG object ``{{ task }}`` the Task object ``{{ macros }}`` a reference to the macros package, described below