简体   繁体   English

气流 - 运行任务,无论上游成功/失败

[英]Airflow - run task regardless of upstream success/fail

I have a DAG which fans out to multiple independent units in parallel. 我有一个DAG,可以并行地向多个独立单元扇出。 This runs in AWS, so we have tasks which scale our AutoScalingGroup up to the maximum number of workers when the DAG starts, and to the minimum when the DAG completes. 这在AWS中运行,因此我们有一些任务可以将我们的AutoScalingGroup扩展到DAG启动时的最大工作数,并在DAG完成时达到最小值。 The simplified version looks like this: 简化版本如下所示:

           | - - taskA - - |
           |               |
scaleOut - | - - taskB - - | - scaleIn
           |               |
           | - - taskC - - |

However, some of the tasks in the parallel set fail occasionally, and I can't get the scaleDown task to run when any of the AC tasks fail. 但是,并行集中的某些任务偶尔会失败,并且当任何AC任务失败时,我无法运行scaleDown任务。

What's the best way to have a task execute at the end of the DAG, once all other tasks have completed (success or fail)? 一旦所有其他任务完成(成功或失败),在DAG结束时执行任务的最佳方法是什么? The depends_on_upstream setting sounded like what we needed, but didn't actually do anything based on testing. depends_on_upstream设置听起来像我们需要的,但实际上并没有根据测试做任何事情。

All operators have an argument trigger_rule which can be set to 'all_done' , which will trigger that task regardless of the failure or success of the previous task(s). 所有运算符都有一个参数trigger_rule ,可以设置为'all_done' ,无论前一个任务的失败或成功如何,都会触发该任务。

You could set the trigger rule for the task you want to run to 'all_done' instead of the default 'all_success' . 您可以将要运行的任务的触发器规则设置为'all_done'而不是默认的'all_success'

A simple bash operator task with that argument would look like: 使用该参数的简单bash运算符任务如下所示:

task = BashOperator(
    task_id="hello_world",
    bash_command="echo Hello World!",
    trigger_rule="all_done",
    dag=dag
    )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM