Seems dependencies accross Dags don't work ?
I'm trying to set upstream task in upstream_dag,downstream task in downstream_dag. But it seems it does not work.
- upstream
from datetime import datetime, timedelta
from airflow.operators import BashOperator, EmailOperator
from airflow.models import DAG
args = {
'owner': 'tony',
'start_date': datetime.strptime('2015-09-01 00:00:00', '%Y-%m-%d %H:%M:%S'),
'email': ['xxx'],
'email_on_failure': True,
'email_on_retry': True,
'retries': 3,
'retry_interval': timedelta(minutes=5),
'schedule_interval': timedelta(minutes=5),
}
dag = DAG(dag_id='upstream_dag', default_args=args)
ETL_HOME = '/home/prod/deepdive'
step_one = BashOperator(
task_id='upstream',
bash_command=(
"export ETL_HOME=%(ETL_HOME)s; "
" echo ${ETL_HOME} "
) % {
'ETL_HOME': ETL_HOME,
},
dag=dag)
- downstream
from datetime import datetime, timedelta
from airflow.operators import BashOperator, EmailOperator
from airflow.models import DAG
from upstream import step_one as up_task
args = {
'owner': 'tony',
'start_date': datetime.strptime('2015-09-01 00:00:00', '%Y-%m-%d %H:%M:%S'),
'email': MAIL_TO,
'email_on_failure': True,
'email_on_retry': True,
'retries': 3,
'retry_interval': timedelta(minutes=5),
'schedule_interval': timedelta(minutes=5),
}
dag = DAG(dag_id='downstream_dag', default_args=args)
ETL_HOME = '/home/prod/deepdive'
down = BashOperator(
task_id='donwstream',
bash_command=(
"export ETL_HOME=%(ETL_HOME)s; "
" echo "downstream_dag" "
) % {
'ETL_HOME': ETL_HOME,
},
dag=dag)
down.set_upstream(up_task)
It will log out : [2015-09-01 15:38:16,983] {models.py:778} WARNING - Dependencies not met yet
For cross dag dependencies, use ExternalTaskSensor, it allows you to wait for task completion within a different dag
Thanks @jomar83 ,I will have a try.
Your welcome. In your case it would look something like this:
et = ExternalTaskSensor(
external_dag_id='upstream_dag',
external_task_id='upstream',
dag=dag,
task_id='wait_for_upstream')
down definition here
down.set_upstream(et)
Still dont work,Do I need to set execution_date? both the tasks's execution_date I'm running is 2015-08-31 00:00:00
from datetime import datetime, timedelta
from airflow.operators import BashOperator, EmailOperator
from airflow.models import DAG
from airflow.operators import ExternalTaskSensor
MAIL_TO = [
'[email protected]'
]
args = {
'owner': 'tony',
'start_date': datetime.strptime('2015-08-31 12:00:00', '%Y-%m-%d %H:%M:%S'),
'email': MAIL_TO,
'email_on_failure': True,
'email_on_retry': True,
'retries': 3,
'retry_interval': timedelta(minutes=5),
'schedule_interval': timedelta(minutes=5),
}
dag = DAG(dag_id='downstream_dag', default_args=args)
ETL_HOME = '/home/prod/deepdive'
et = ExternalTaskSensor(
external_dag_id='upstream_dag',
external_task_id='upstream',
dag=dag,
task_id='wait_for_upstream'
)
down = BashOperator(
task_id='downstream',
bash_command=(
"export ETL_HOME=%(ETL_HOME)s; "
" echo 'downstream_dag' "
) % {
'ETL_HOME': ETL_HOME,
},dag=dag)
down.set_upstream(et)
can you elaborate on what issue you're facing? As long as your upstream dag is called "upstream_dag" and the task your waiting for in that dag is called "upstream", your down task should start shortly after the upstream task has completed successfully... In the web ui the "et" Sensor should be running while the upstream task hasn't finished.
After I have ran the upstream, and the status I saw is success. Then I ran downstream, but it still can not generate a TI,and log out:Dependencies not met yet. BTW, I did not seee any "et" Sensor in web ui. I'm running v1.41. Appriciate for your help.
There's a refresh button on the DAGs page (the rightmost icon in the table view), that indicates to the web server to refresh that dag's definition. Also schedule_interval is a DAG parameter, not a task parameter.
Are you trying to run the DAG every 5 minutes?
Great, thanks! It works well now. At first, I'm thinking the scheduler will auto generate TIs by the schedule_interval parameter, It's just a demo for upcoming depency accross dags usage,so I need to schedule 5 mins to see whether it's ok. Close it.