{"action":"created","issue":{"url":"https://api.github.com/repos/airbnb/airflow/issues/112","labels_url":"https://api.github.com/repos/airbnb/airflow/issues/112/labels{/name}","comments_url":"https://api.github.com/repos/airbnb/airflow/issues/112/comments","events_url":"https://api.github.com/repos/airbnb/airflow/issues/112/events","html_url":"https://github.com/airbnb/airflow/issues/112","id":93943383,"number":112,"title":"Need to convert end_date to epoch seconds in template in BashOperator","user":{"login":"r39132","id":581734,"avatar_url":"https://avatars.githubusercontent.com/u/581734?v=3","gravatar_id":"","url":"https://api.github.com/users/r39132","html_url":"https://github.com/r39132","followers_url":"https://api.github.com/users/r39132/followers","following_url":"https://api.github.com/users/r39132/following{/other_user}","gists_url":"https://api.github.com/users/r39132/gists{/gist_id}","starred_url":"https://api.github.com/users/r39132/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/r39132/subscriptions","organizations_url":"https://api.github.com/users/r39132/orgs","repos_url":"https://api.github.com/users/r39132/repos","events_url":"https://api.github.com/users/r39132/events{/privacy}","received_events_url":"https://api.github.com/users/r39132/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-07-09T03:19:23Z","updated_at":"2015-07-16T03:26:32Z","closed_at":null,"body":"Hi!\r\nI am executing a remote spark job and need to pass the \"start_date\" as a parameter to the spark job. Unfortunately, the remote spark job is expecting the date as epoch seconds, so I need a template for ` {{ end_date.strftime('%s') }` as shown in the example below. How do I accomplish this? Also, what is the macro for start-date? I feel that what I really want is start-date, not end-date.\r\n\r\n```\r\n# Convert the end_date to epoch seconds\r\naggregate_data_spark_job = BashOperator(\r\n    task_id='aggregate_data_spark_job',\r\n    bash_command=\"ssh -i ~/.ssh/id_rsa_spark root@10.10.2.157 '. /root/.bash_profile; /root/run_aggregation.sh --start_ts {{ end_date.strftime('%s') }}'\" ,\r\n    dag=dag)\r\naggregate_data_spark_job.set_upstream(clean_up_db_tables_job)\r\n```"},"comment":{"url":"https://api.github.com/repos/airbnb/airflow/issues/comments/121816266","html_url":"https://github.com/airbnb/airflow/issues/112#issuecomment-121816266","issue_url":"https://api.github.com/repos/airbnb/airflow/issues/112","id":121816266,"user":{"login":"r39132","id":581734,"avatar_url":"https://avatars.githubusercontent.com/u/581734?v=3","gravatar_id":"","url":"https://api.github.com/users/r39132","html_url":"https://github.com/r39132","followers_url":"https://api.github.com/users/r39132/followers","following_url":"https://api.github.com/users/r39132/following{/other_user}","gists_url":"https://api.github.com/users/r39132/gists{/gist_id}","starred_url":"https://api.github.com/users/r39132/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/r39132/subscriptions","organizations_url":"https://api.github.com/users/r39132/orgs","repos_url":"https://api.github.com/users/r39132/repos","events_url":"https://api.github.com/users/r39132/events{/privacy}","received_events_url":"https://api.github.com/users/r39132/received_events","type":"User","site_admin":false},"created_at":"2015-07-16T03:26:32Z","updated_at":"2015-07-16T03:26:32Z","body":"I tried \r\n```{{ (execution_date + timedelta(1)).strftime('%s') }}```\r\n\r\nas in \r\n```\r\n# Operator : Read the parquet data and generate aggregate data\r\n# Convert the end_date to epoch seconds\r\naggregate_data_spark_job = BashOperator(\r\n    task_id='aggregate_data_spark_job',\r\n    bash_command=\"ssh -i ~/.ssh/id_rsa_spark root@10.10.2.157 '. /root/.bash_profile; /root/run_aggregation.sh {{ (execution_date - timedelta(5)).strftime('%s') }} {{ execution_date.strftime('%s') }}'\" ,\r\n    dag=dag)\r\naggregate_data_spark_job.set_upstream(clean_up_db_tables_job)\r\n```\r\nBut, I get the following exception : \r\n```\r\n2015-07-15 20:23:52,583 - root - ERROR - 'timedelta' is undefined\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python2.7/site-packages/airflow-1.1.1-py2.7.egg/airflow/models.py\", line 818, in run\r\n    self.render_templates()\r\n  File \"/usr/local/lib/python2.7/site-packages/airflow-1.1.1-py2.7.egg/airflow/models.py\", line 918, in render_templates\r\n    result = rt(content, jinja_context)\r\n  File \"/usr/local/lib/python2.7/site-packages/airflow-1.1.1-py2.7.egg/airflow/models.py\", line 1181, in render_template\r\n    return template.render(**context)\r\n  File \"/usr/local/lib/python2.7/site-packages/jinja2/environment.py\", line 969, in render\r\n    return self.environment.handle_exception(exc_info, True)\r\n  File \"/usr/local/lib/python2.7/site-packages/jinja2/environment.py\", line 742, in handle_exception\r\n    reraise(exc_type, exc_value, tb)\r\n  File \"<template>\", line 1, in top-level template code\r\nUndefinedError: 'timedelta' is undefined\r\n```\r\n\r\n"}}