捕捉到 Airflow Dags 的 kill 信号

Catching kill signals to Airflow Dags

tl;博士

自定义运算符执行另一个运行一段时间的子流程(devops 管道)。如果任务现在被手动中断,子进程仍然在运行 运行。 有没有可能捕捉到信号,然后也交给子进程?


触发器执行 Azure Devops 管道,通过自定义运算符完成 class。它运行 post 请求以启动管道,然后等待(戳)它完成。

如果 dag 或任务在此期间被终止(用户在 UI 中中断进程),Azure 管道仍然运行而不会被取消。 到目前为止,我的解决方案是编写异步。检查 Dag(任务)是否仍然可用(或已删除)的函数。

不过,更欢迎原生的 Airflow 解决方案。

注意:我用的是1.10.15,不能撞到2.x

是的。您的自定义运算符应覆盖 BaseOperator:

中的 on_kill 方法
    def on_kill(self) -> None:
        """
        Override this method to cleanup subprocesses when a task instance
        gets killed. Any use of the threading, subprocess or multiprocessing
        module within an operator needs to be cleaned up or it will leave
        ghost processes behind.
        """

它一直存在 - 即使在 Airflow 1.10 中也是如此