Skip to content

Commit

Permalink
[AIRFLOW-815] Add prev/next execution dates to template variables
Browse files Browse the repository at this point in the history
This patch adds the previous/next execution dates
to the default variables available in a template.

Closes apache#2033 from danielvdende/add-execution-dates
  • Loading branch information
danielvdende authored and bolkedebruin committed Jan 29, 2017
1 parent 3ca287d commit a67e439
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions airflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,9 @@ def get_template_context(self, session=None):
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('-', '')
Expand Down Expand Up @@ -1543,6 +1546,8 @@ def __repr__(self):
'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,
Expand Down
2 changes: 2 additions & 0 deletions docs/code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a67e439

Please sign in to comment.