BashOperator不运行bash命令apache气流

时间:2018-09-04 14:18:42

标签: airflow

我正在运行气流教程。 tutorial.py中的内容如下:

"""
Code that goes along with the Airflow located at:
http://airflow.readthedocs.org/en/latest/tutorial.html
"""
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(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)

tutorial.py位于〜/ airflow / dags下。通过运行airflow list_dags,我可以在列表末尾看到tutorial。 但是,当我运行airflow test tutorial print_date 2018-09-04时,它仅显示:

[2018-09-04 22:14:43,096] {__init__.py:51} INFO - Using executor SequentialExecutor
[2018-09-04 22:14:43,199] {models.py:258} INFO - Filling up the DagBag from /Users/chenyuanfei/airflow/dags

没有别的。 我在OSX上使用apche-airflow 1.10。 如何正确运行脚本?

1 个答案:

答案 0 :(得分:0)

我怀疑是否是因为我的Mac上同时装有airflow1.8和apache-airflow1.10。 我同时卸载了这两个软件,然后重新安装了airflow1.8,这一次它起作用了