Airflow BashOperator不起作用,但PythonOperator起作用 [英] Airflow BashOperator doesn't work but PythonOperator does

查看:519
本文介绍了Airflow BashOperator不起作用,但PythonOperator起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I seem to have a problem with BashOperator. I'm using Airflow 1.10 installed on CentOS in a Miniconda environment (Python 3.6) using the package on Conda Forge.

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

When I run airflow test tutorial pyHi 2018-01-01 the output is "Hello world!" as expected.

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

However, when I run airflow test tutorial print_date 2018-01-01 or airflow test tutorial templated 2018-01-01 nothing happens.

这是Linux shell输出:

This is the Linux shell output:

(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

(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

我的DAG配置文件基于 Airflow教程,如下所示.

My DAG configuration file, which is based on the Airflow tutorial, is shown below.

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

Technically it's not that the BashOperator doesn't work, it's just that you don't see the stdout of the Bash command in the Airflow logs. This is a known issue and a ticket has already been filed on Airflow's issue tracker: https://issues.apache.org/jira/browse/AIRFLOW-2674

BashOperator起作用的事实证明是,如果您使用运行sleep运算符,

The proof of the fact that BashOperator does work is that if you run your sleep operator with

airflow test tutorial sleep 2018-01-01

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

you will have to wait 5 seconds before it terminates, which is the behaviour you'd expect from the Bash sleep command.

这篇关于Airflow BashOperator不起作用,但PythonOperator起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆