简体   繁体   English

如何从 UI 停止/终止 Airflow 任务

[英]How to stop/kill Airflow tasks from the UI

How can I stop/kill a running task on Airflow UI?如何在 Airflow UI 上停止/终止正在运行的任务? I am using LocalExecutor .我正在使用LocalExecutor Even if I use CeleryExecutor , how do can I kill/stop the running task?即使我使用CeleryExecutor ,我怎样才能杀死/停止正在运行的任务?

In the DAGs screen you can see the running tasks:在 DAG 屏幕中,您可以看到正在运行的任务:

在此处输入图像描述

Example例子

On 'Recent Tasks' press the running icon and Airflow will automatically run the search query with the filters for the Dag Id and State equal to 'running' and show the results on the Task Instances screen (you can find it manually on the tab Browse > Task Instances).在“最近的任务”上按运行图标,Airflow 将自动运行搜索查询,其中 Dag Id 和状态的过滤器等于“正在运行”,并在“任务实例”屏幕上显示结果(您可以在“浏览”选项卡上手动找到它> 任务实例)。

There you can select the presented tasks and set them to another state or delete them.在那里,您可以选择呈现的任务并将它们设置为另一种状态或删除它们。

Please notice that if the DAG is currently running, the Airflow scheduler will start again the tasks you delete.请注意,如果 DAG 当前正在运行,Airflow 调度程序将重新启动您删除的任务。 So either you stop the DAG first by changing its state or stop the scheduler (if you are running on a test environment).因此,要么首先通过更改其状态来停止 DAG,要么停止调度程序(如果您在测试环境中运行)。

Simply set the task to failed state will stop the running task.只需将任务设置为失败状态将停止正在运行的任务。

[2019-09-17 23:53:28,040] {logging_mixin.py:82} INFO - [2019-09-17 23:53:28,039] {jobs.py:2695} WARNING - State of this instance has been externally set to failed. Taking the poison pill.
[2019-09-17 23:53:28,041] {helpers.py:240} INFO - Sending Signals.SIGTERM to GPID 20977

from airflow gitter (@villasv)来自气流 gitter (@villasv)

" Not gracefully, no. You can stop a dag (unmark as running) and clear the tasks states or even delete them in the UI. The actual running tasks in the executor won't stop, but might be killed if the executor realizes that it's not in the database anymore . " " 不优雅,不。您可以停止 dag(取消标记为正在运行)并清除任务状态,甚至在 UI 中删除它们。执行器中实际运行的任务不会停止,但如果执行器意识到,可能会被杀死它不再在数据库中了。”

Set task to failed state:将任务设置为失败状态:

  1. Click task点击任务在此处输入图像描述

  2. Set task to "Failed" state将任务设置为“失败”状态在此处输入图像描述

  3. All subsequent tasks (if there are any) will also be marked as failed:所有后续任务(如果有的话)也将被标记为失败: 在此处输入图像描述

As menioned by Pablo and Jorge pausing the Dag will not stop the task from being executed if the execution already started.正如 Pablo 和 Jorge 所提到的,如果执行已经开始,暂停 Dag 不会停止执行任务。 However there is a way to stop a running task from the UI but it's a bit hacky.然而,有一种方法可以从 UI 停止正在运行的任务,但它有点 hacky。

When the task is on running state you can click on CLEAR this will call job.kill() the task will be set to shut_down and moved to up_for_retry immediately hence it is stopped.当任务处于running状态时,您可以单击CLEAR这将调用job.kill()任务将被设置为shut_down并立即移动到up_for_retry因此它被停止。

Clearly Airflow did not meant for you to clear tasks in Running state however since Airflow did not disable it either you can use it as I suggested.显然,Airflow 并不意味着您要清除处于Running状态的任务,但是由于 Airflow 没有禁用它,所以您可以按照我的建议使用它。 Airflow meant CLEAR to be used with failed , up_for_retry etc... Maybe in the future the community will use this bug(?) and implement this as a functionality with "shut down task" button. Airflow 意味着CLEAR可以与failedup_for_retry等一起使用......也许将来社区会使用这个错误(?)并将其实现为带有“关闭任务”按钮的功能。

AirFlow Version: v2.2.2 and above AirFlow 版本:v2.2.2 及以上

  1. Go to AirFlow home page and search you Dag.转到 AirFlow 主页并搜索您的 Dag。
  2. Under the "Runs" status column press on the running status(green circle).在“运行”状态栏下按运行状态(绿色圆圈)。

在此处输入图像描述

  1. You can choose a specific DAG run or, in the check box above choose all.您可以选择特定的 DAG 运行,或者在上面的复选框中选择全部。

在此处输入图像描述

Then on the "Action" button, choose your relevant action然后在“操作”按钮上,选择您的相关操作

在此处输入图像描述

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

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