python - 在 Apache Airflow 中,如何将脚本设置为任务?
问题描述
我正在尝试遵循本教程
https://airflow.apache.org/docs/stable/tutorial.html
其中有以下代码
"""
Code that goes along with the Airflow tutorial located at:
https://github.com/apache/airflow/blob/master/airflow/example_dags/tutorial.py
"""
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta
default_args = {
'owner': 'Airflow',
'depends_on_past': False,
'start_date': datetime(2015, 6, 1),
'email': ['airflow@example.com'],
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
# 'queue': 'bash_queue',
# 'pool': 'backfill',
# 'priority_weight': 10,
# 'end_date': datetime(2016, 1, 1),
}
dag = DAG('tutorial', default_args=default_args, schedule_interval=timedelta(days=1))
# t1, t2 and t3 are examples of tasks created by instantiating operators
t1 = BashOperator(
task_id='print_date',
bash_command='date',
dag=dag)
t2 = BashOperator(
task_id='sleep',
bash_command='sleep 5',
retries=3,
dag=dag)
templated_command = """
{% for i in range(5) %}
echo "{{ ds }}"
echo "{{ macros.ds_add(ds, 7)}}"
echo "{{ params.my_param }}"
{% endfor %}
"""
t3 = BashOperator(
task_id='templated',
bash_command=templated_command,
params={'my_param': 'Parameter I passed in'},
dag=dag)
t2.set_upstream(t1)
t3.set_upstream(t1)
我有一些 python 脚本(带有 args),我试图将它们设置为任务。我猜我需要以某种方式使用 BashOperator,但是当我查找它时,它并没有真正说明如何为其设置脚本
解决方案
推荐阅读
- javascript - 从网页中提取电话号码,然后对其进行处理
- java - Android Studio 不排除传递依赖并抱怨类冲突
- python - 无法使用熊猫时间戳编写有效的镶木地板文件
- javascript - 在页面加载时触发 jQuery 函数
- javascript - XML 通信问题。无法将数据保存到 XML
- ios - 使用 cordova-plugin-facebook4@4.2.1 “用户已取消。” 调用登录方法后立即抛出错误
- python-3.x - python opencv 显示 gstreamer videotestsrc
- spring-webflux - 发布者的动态集都通过相同的通量发射
- c# - 在 Unity3D 上建模纬度和经度的困难
- ios - tabBarItem 图像质量不佳