我似乎遇到了BashOperator的问题.我正在使用Conda Forge上的软件包在Miniconda环境(Python 3.6)中使用CentOS上安装的Airflow 1.10.
当我运行气流测试教程pyHi 2018-01-01时输出为“Hello world!”正如所料.
但是,当我运行气流测试教程print_date 2018-01-01或
气流测试教程模板2018-01-01没有任何反应.
这是Linux shell输出:
(etl)[root @ VIRT02气流]#气流测试教程睡眠2015-06-01
[2018-09-28 19:56:09,727] {__ init__.py:51} INFO – 使用执行程序SequentialExecutor
[2018-09-28 19:56:09,962] {models.py:258}信息 – 从/ root / airflow / dags填充DagBag
我的DAG配置文件基于Airflow tutorial,如下所示.
from airfl ow import DAG
from airflow.operators.bash_operator import BashOperator
from airflow.operators.python_operator import PythonOperator
from datetime import datetime, timedelta
import test
default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime(2010, 1, 1),
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedelta(minutes=5),
}
dag = DAG(
'tutorial',
'My first attempt',
schedule_interval=timedelta(days=1),
default_args=default_args,
)
# 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)
t4 = BashOperator(
task_id='hi',
bash_command = 'test.sh',
dag=dag,
)
t5 = PythonOperator(
task_id='pyHi',
python_callable=test.main,
dag=dag,
)
t2.set_upstream(t1)
t3.set_upstream(t1)
解决方法:
从技术上讲,并不是BashOperator不起作用,只是你没有在Airflow日志中看到Bash命令的标准输出.这是一个已知问题,并且已经在Airflow的问题跟踪器上提交了一张票:https://issues.apache.org/jira/browse/AIRFLOW-2674
证明BashOperator能够正常工作的事实是,如果你运行睡眠运算符
airflow test tutorial sleep 2018-01-01
你必须在它终止之前等待5秒,这是你期望从Bash sleep命令中获得的行为.