msemochkin

long_task_dag

Jan 13th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. from airflow import DAG
  2. from airflow.operators.python_operator import PythonOperator
  3. from datetime import datetime, timedelta
  4.  
  5. import time
  6.  
  7. schedule_interval = '45 7 * * *'
  8. default_args = {
  9.     'owner': 'user',
  10.     'start_date': datetime(2017, 1, 13, 7, 30),
  11.     'email': ['[email protected]']
  12. }
  13.  
  14. dag = DAG('long_task',
  15.           schedule_interval = schedule_interval,
  16.           default_args=default_args)
  17.  
  18. def run(n):
  19.     time.sleep(n)
  20.  
  21. task1 = PythonOperator(task_id='task1',
  22.                        execution_timeout=timedelta(hours=2),
  23.                        python_callable=run,
  24.                        op_kwargs={'n': 5400},
  25.                        dag=dag)
  26. task2 = PythonOperator(task_id='task2',
  27.                        execution_timeout=timedelta(hours=2),
  28.                        python_callable=run,
  29.                        op_kwargs={'n': 1800},
  30.                        dag=dag)
  31.  
  32. task1 >> task2
Add Comment
Please, Sign In to add comment