I need to pass a job_id parameter to my object DatabricksRunNowOperator(). The job_id is the result of executing the databricks jobs create --json '{myjson}
command.
$ databricks jobs create --json '{myjson}'
{job_id: 12}
import os
import subprocess
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.contrib.operators.databricks_operator import DatabricksRunNowOperator
def pull_function():
returned_output = subprocess.check_output("echo ti.xcom_pull(key='jobid_CreateCreateRobot')")
return returned_output
dag_CreateRobot = DAG(dag_id='CreateRobot',
default_args={'owner': 'eric',
'email': [],
'depends_on_past': False,
'start_date':'2019-09-16 16:48:28.803023',
'provide_context': True},
schedule_interval='@once')
CreateRobot = BashOperator(dag=dag_CreateRobot,
task_id='CreateRobot',
bash_command="databricks jobs create --json '{myjson}')")\
RunRobot = DatabricksRunNowOperator(dag=dag_CreateRobot,
task_id=ti.xcom_pull('RunCreateRobot'),
job_id=pull_function(),
databricks_conn_id='myconn',
json={'token': 'mytoken' })
RunRobot.set_upstream(CreateRobot)
I wrote this code for explaining my goal but it does not work. How can I do for using the result of a BashOperator task into other task that depends of it?