dag8_test2.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from datetime import timedelta
  2. from airflow.models import DAG,Variable
  3. from airflow.utils.dates import days_ago
  4. from airflow.operators.bash_operator import BashOperator
  5. from airflow.contrib.operators.ssh_operator import SSHOperator
  6. from airflow.operators.python_operator import PythonOperator,BranchPythonOperator
  7. from airflow.contrib.hooks.ssh_hook import SSHHook
  8. default_args = {
  9. 'owner': 'airflow',
  10. 'depends_on_past': False,
  11. 'start_date': days_ago(2),
  12. 'email_on_failure': False,
  13. 'email_on_retry': False,
  14. 'retries': 1,
  15. 'retry_delay': timedelta(minutes=5),
  16. }
  17. dag = \
  18. DAG(
  19. dag_id='dag8_test2',
  20. catchup=False,
  21. schedule_interval="0 */2 * * *",
  22. max_active_runs=1,
  23. tags=['orwell','hpc'],
  24. default_args=default_args)
  25. orwell_ssh_hook = \
  26. SSHHook(
  27. key_file=Variable.get('hpc_ssh_key_file'),
  28. username=Variable.get('hpc_user'),
  29. remote_host='orwell.hh.med.ic.ac.uk')
  30. with dag:
  31. generate_file_list = \
  32. SSHOperator(
  33. task_id = 'generate_file_list',
  34. dag = dag,
  35. ssh_hook = orwell_ssh_hook,
  36. queue='hpc_4G',
  37. command = 'python /home/igf/igf_code/t1.py')
  38. branch_to = \
  39. BranchPythonOperator(
  40. task_id='calculate_new_worker_size_and_branch',
  41. dag=dag,
  42. python_callable=lambda: ['copy_files_to_hpc1',],
  43. queue='hpc_4G')
  44. copy_files_to_hpc1 = \
  45. BashOperator(
  46. task_id = 'copy_files_to_hpc1',
  47. dag = dag,
  48. queue='hpc_4G',
  49. bash_command = 'bash /project/tgu/data2/airflow_test/github/t1.sh ')
  50. copy_files_to_hpc2 = \
  51. BashOperator(
  52. task_id = 'copy_files_to_hpc2',
  53. dag = dag,
  54. queue='hpc_4G',
  55. bash_command = 'bash /project/tgu/data2/airflow_test/github/t2.sh ')
  56. generate_file_list >> branch_to >> [copy_files_to_hpc1,copy_files_to_hpc2]