Skip to content

Commit

Permalink
Show rendered templates from the CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Jan 31, 2016
1 parent 8ca9687 commit 265d47c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion airflow/bin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import subprocess
import textwrap
from datetime import datetime

from builtins import input
Expand Down Expand Up @@ -266,7 +267,6 @@ def list_tasks(args):


def test(args):

args.execution_date = dateutil.parser.parse(args.execution_date)
dagbag = DagBag(process_subdir(args.subdir))
if args.dag_id not in dagbag.dags:
Expand All @@ -281,6 +281,24 @@ def test(args):
ti.run(force=True, ignore_dependencies=True, test_mode=True)


def render(args):
args.execution_date = dateutil.parser.parse(args.execution_date)
dagbag = DagBag(process_subdir(args.subdir))
if args.dag_id not in dagbag.dags:
raise AirflowException('dag_id could not be found')
dag = dagbag.dags[args.dag_id]
task = dag.get_task(task_id=args.task_id)
ti = TaskInstance(task, args.execution_date)
ti.render_templates()
for attr in task.__class__.template_fields:
print(textwrap.dedent("""\
# ----------------------------------------------------------
# property: {}
# ----------------------------------------------------------
{}
""".format(attr, getattr(task, attr))))


def clear(args):
logging.basicConfig(
level=settings.LOGGING_LEVEL,
Expand Down Expand Up @@ -703,4 +721,15 @@ def get_parser():
nargs='?', default=configuration.get('kerberos', 'principal'))
parser_kerberos.set_defaults(func=kerberos)

ht = "Render a task instance's template(s)"
parser_render = subparsers.add_parser('render', help=ht)
parser_render.add_argument("dag_id", help="The id of the dag to check")
parser_render.add_argument("task_id", help="The task_id to check")
parser_render.add_argument(
"execution_date", help="The execution date to check")
parser_render.add_argument(
"-sd", "--subdir", help=subdir_help,
default=DAGS_FOLDER)
parser_render.set_defaults(func=render)

return parser
2 changes: 1 addition & 1 deletion airflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ def render_templates(self):
for attr in task.__class__.template_fields:
content = getattr(task, attr)
if content:
rendered_content = self.task.render_template(content, jinja_context)
rendered_content = rt(content, jinja_context)
setattr(task, attr, rendered_content)

def email_alert(self, exception, is_retry=False):
Expand Down

0 comments on commit 265d47c

Please sign in to comment.