Airflow BashOperator不起作用,但PythonOperator起作用

时间:2018-10-02 09:58:27

标签: python linux bash airflow

我似乎对BashOperator有问题。我正在使用Conda Forge上的软件包在Miniconda环境(Python 3.6)中的CentOS上安装的Airflow 1.10。

当我运行airflow test tutorial pyHi 2018-01-01时,输出为“ Hello world!”。如预期的那样。

但是,当我运行airflow test tutorial print_date 2018-01-01airflow test tutorial templated 2018-01-01什么也没发生。

这是Linux shell输出:

(etl) [root@VIRT02 airflow]# airflow test tutorial sleep 2015-06-01 [2018-09-28 19:56:09,727] {__init__.py:51} INFO - Using executor SequentialExecutor [2018-09-28 19:56:09,962] {models.py:258} INFO - Filling up the DagBag from /root/airflow/dags

我的基于Airflow tutorial的DAG配置文件如下所示。

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)

1 个答案:

答案 0 :(得分:5)

从技术上讲,这并不是BashOperator不起作用的原因,只是您没有在Airflow日志中看到Bash命令的标准输出。这是一个已知问题,并且已经在Airflow的问题跟踪器上提交了票证:https://issues.apache.org/jira/browse/AIRFLOW-2674

BashOperator起作用的事实证明是,如果您使用{p> 1运行您的sleep

airflow test tutorial sleep 2018-01-01

您必须等待5秒钟才能终止,这是Bash sleep命令所期望的行为。