t3 = BashOperator( task_id='templated', depends_on_past=False, bash_command=templated_command, params={'my_param': 'Parameter I passed in'}, dag=dag) t2.set_upstream(t1) t3.set_upstream(t1) 这里t1 和 t2 都很容易理解,
hive -f "/home/airflow/hive1.sql" -hivevar tbname=%s ''' % str1 t1 = BashOperator( task_id='hivesh2', bash_command=bash_cmd, dag=dag) 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 创建hive sql文件: insert overwrite table ...
bash_command='python /Users/hong/Desktop/Develop/my_airflow/operations/first_operation.py a', dag=dag, ) t2 = BashOperator( task_id='write_b', bash_command='python /Users/hong/Desktop/Develop/my_airflow/operations/first_operation.py b', dag=dag, ) t3 = BashOperator( task_id='write_...
创建TASK 一个TASK可以使用某个具体的Operator模板,例如上文提到的 BashOperator、PythonOperator,也可以使用自己实现的Operator。 BashOperator from airflow.operators.bash import BashOperator bash_task = BashOperator( task_id='print_date', # 这里也可以写脚本文件路径 bash_command='date', ) PythonOperator ...
BashOperator- executes a bash command 执行Linux命令 PythonOperator- calls an arbitrary Python function 执行Python代码 EmailOperator- sends an email 发送邮件的 其他 MySqlOperator PostgresOperator MsSqlOperator OracleOperator JdbcOperator DockerOperator ...
bash_command='echo "Executing Bash Task"', dag=dag, ) # 使用SqliteOperator执行SQL查询 task_sqlite = SqliteOperator( task_id='task_sqlite', sql='SELECT * FROM my_table;', sqlite_conn_id='my_sqlite_conn', dag=dag, ) 5.3 定时调度:使用Cron表达式 ...
bash_command, shell=True, stdout=PIPE, stderr=PIPE)out, err =sp.communicate() sp.wait()logging.info("Command STDOUT:\n"+out)iferr: logging.error(err)ifsp.returncode: raise Exception("Bash command failed") 将不确定元素在执行时变成确定task_copy=copy.copy(self.task)forattrintask_copy.__...
BashOperator默认执行脚本时,默认从/tmp/airflow**临时目录查找对应脚本,由于临时目录名称不定,这里建议执行脚本时,在“bash_command”中写上绝对路径。如果要写相对路径,可以将脚本放在/tmp目录下,在“bash_command”中执行命令写上“sh ../xxx.sh”也可以。
task4 =BashOperator(task_id='task4', bash_command='echo "Hello from task4"') task1 >> task2 >> [task3, task4] 3.配置与部署 将DAG文件放入Airflow的dags目录,启动Airflow服务(包括Scheduler、Web Server、Worker)。在Web UI中可查看、触发、监控DAG运行。
bash_command='date', dag=dag) t1 >> t2 ``` 该文件创建一个简单的 DAG,只有三个运算符,两个 BaseOperator ,也就是执行 Bash 命令分别打印日期以及休眠 5 秒;另一个为 PythonOperator 在执行任务时调用 print_hello() 函数。 文件创建好后,放置到 ${AIRFLOW_HOME}/dags,airflow 自动读取该DAG。