以编程方式清除气流任务实例的状态

编程入门 行业动态 更新时间:2024-10-17 07:24:52
本文介绍了以编程方式清除气流任务实例的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在DAG A 完成执行后清除DAG B中的任务。 A和B都是预定的 DAG。

I want to clear the tasks in DAG B when DAG A completes execution. Both A and B are scheduled DAGs.

是否有个操作符 /路清除任务状态并以编程方式重新运行DAG B?

Is there any operator/way to clear the state of tasks and re-run DAG B programmatically?

我知道 CLI选项和Web UI选项可清除任务。

I'm aware of the CLI option and Web UI option to clear the tasks.

推荐答案

我建议在这里远离CLI!

I would recommend staying away from CLI here!

与通过BashOperator和/或CLI模块相比,引用对象时dags /任务的气流功能要好得多。

The airflow functionality of dags/tasks are much better exposed when referencing the objects, as compared to going through BashOperator and/or CLI module.

在上添加python操作dag A ,名为 clear_dag_b,它从 dags 文件夹(模块)中导入dag_b,并且该操作是:

Add a python operation to dag A named "clear_dag_b", that imports dag_b from the dags folder(module) and this:

from dags.dag_b import dag as dag_b def clear_dag_b(**context): exec_date = context[some date object, I forget the name] dag_b.clear(start_date=exec_date, end_date=exec_date)

重要!如果您由于某种原因未将dag_b计划时间与开始日期/结束日期进行匹配或重叠,则clear()操作将丢失dag执行。此示例假设dag A 和 B 的安排相同,并且您只想从 B 清除日期 X ,当 A 执行第 X

Important! If you for some reason do not match or overlap the dag_b schedule time with start_date/end_date, the clear() operation will miss the dag executions. This example assumes dag A and B are scheduled identical, and that you only want to clear day X from B, when A executes day X

检查dag_b是否已经运行可能是有意义的是否在清除之前

It might make sense to include a check for whether the dag_b has already run or not, before clearing:

dab_b_run = dag_b.get_dagrun(exec_date) # returns None or a dag_run object

更多推荐

以编程方式清除气流任务实例的状态

本文发布于:2023-11-23 19:03:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622546.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:气流   实例   状态   方式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!