使用CLI运行命令在Airflow中触发任务

时间:2018-08-21 19:24:39

标签: python airflow

如何使用CLI中的run命令在Airflow(v1.8.1)DAG中触发特定任务?

DAG

dag = DAG(
    'test_run',
    default_args=default_args,
    schedule_interval=SCHEDULE_INTERVAL,
    catchup=False
)

one = BashOperator(
    task_id='one',
    bash_command='echo 1',
    dag=dag,
)

two = BashOperator(
    task_id='two',
    bash_command='echo 2',
    dag=dag,
)

one.set_downstream(two)

命令

airflow run -i -I -f test_run two 2018-08-21T18:59:51

我尝试了-i-I-f命令,没有任何运气,也没有错误。我还尝试过-A来忽略所有依赖关系,但这无法告诉我命令中没有执行日期。

如果我运行相同的命令但指定了任务one,我可以看到它成功显示在任务实例列表中,但是在完全忽略任务{{1}的同时,我似乎无法运行任务two。 }。

尝试运行one时的实际输出。

two

深入研究日志,我可以看到:

datauser@ubuntu-xenial:/home/vagrant$ AIRFLOW_HOME=~/code/dataprocessing/ /virtualenvs/dataprocessing/bin/airflow run -i -I -f test_run two 2018-08-21T18:59:51
/virtualenvs/dataprocessing/lib/python3.5/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)
[2018-08-21 19:11:51,538] {__init__.py:57} INFO - Using executor CeleryExecutor
[2018-08-21 19:11:51,624] {driver.py:120} INFO - Generating grammar tables from /usr/lib/python3.5/lib2to3/Grammar.txt
[2018-08-21 19:11:51,650] {driver.py:120} INFO - Generating grammar tables from /usr/lib/python3.5/lib2to3/PatternGrammar.txt
Sending to executor.
INFO:root:The key logs/test_run/two/2018-08-21T18:59:51 now contains 101162 bytes

但是[2018-08-21 19:13:49,796] {base_task_runner.py:95} INFO - Subtask: [2018-08-21 19:13:49,795] {models.py:1122} INFO - Dependencies not met for <TaskInstance: test_run.two 2018-08-21 18:59:51 [None]>, dependency 'Trigger Rule' FAILED: Task's trigger rule 'all_success' requires all upstream tasks to have succeeded, but found 1 non-success(es). upstream_tasks_state={'successes': 0, 'upstream_failed': 0, 'done': 0, 'skipped': 0, 'failed': 0}, upstream_task_ids=['one'] 标志不能解决这个问题吗?

如果运行时没有-I标志,但带有-I标志,我会收到相同的错误。

-i -f

1 个答案:

答案 0 :(得分:0)

这是Airflow版本<= 1.8中的错误。确实适用于Airflow版本=> 1.9。