airflow.operators.weekday

模块内容

BranchDayOfWeekOperator

根据当前日期分支到两个任务列表之一。

class airflow.operators.weekday.BranchDayOfWeekOperator(*, follow_task_ids_if_true, follow_task_ids_if_false, week_day, use_task_logical_date=False, use_task_execution_day=False, **kwargs)[源代码]

基类:airflow.operators.branch.BaseBranchOperator

根据当前日期分支到两个任务列表之一。

有关如何使用此操作符的更多信息,请查看指南:BranchDayOfWeekOperator

示例(单天)

from airflow.operators.empty import EmptyOperator

monday = EmptyOperator(task_id="monday")
other_day = EmptyOperator(task_id="other_day")

monday_check = BranchDayOfWeekOperator(
    task_id="monday_check",
    week_day="Monday",
    use_task_logical_date=True,
    follow_task_ids_if_true="monday",
    follow_task_ids_if_false="other_day",
)
monday_check >> [monday, other_day]

示例(使用WeekDay枚举)

# import WeekDay Enum
from airflow.utils.weekday import WeekDay
from airflow.operators.empty import EmptyOperator

workday = EmptyOperator(task_id="workday")
weekend = EmptyOperator(task_id="weekend")
weekend_check = BranchDayOfWeekOperator(
    task_id="weekend_check",
    week_day={WeekDay.SATURDAY, WeekDay.SUNDAY},
    use_task_logical_date=True,
    follow_task_ids_if_true="weekend",
    follow_task_ids_if_false="workday",
)
# add downstream dependencies as you would do with any branch operator
weekend_check >> [workday, weekend]
参数
  • follow_task_ids_if_true (str | Iterable[str]) – 如果满足条件,则要遵循的 task_id、task_group_id 或 task_ids 和/或 task_group_ids 列表。

  • follow_task_ids_if_false (str | Iterable[str]) – 如果不满足条件,则要遵循的 task_id、task_group_id 或 task_ids 和/或 task_group_ids 列表。

  • week_day (str | Iterable[str] | airflow.utils.weekday.WeekDay | Iterable[airflow.utils.weekday.WeekDay]) –

    要检查的星期几(全名)。或者,也可以使用集合提供一组日期。示例值

    • "MONDAY",

    • {"Saturday", "Sunday"}

    • {WeekDay.TUESDAY}

    • {WeekDay.SATURDAY, WeekDay.SUNDAY}

    要使用 WeekDay 枚举,请从 airflow.utils.weekday 导入它

  • use_task_logical_date (bool) – 如果 True,则使用任务的逻辑日期与 is_today 进行比较。执行日期对于回填很有用。如果 False,则使用系统的星期几。

  • use_task_execution_day (bool) – 已弃用的参数,与 use_task_logical_date 的效果相同

choose_branch(context)[源代码]

选择要运行的分支的抽象方法。

子类应实现此方法,运行任何必要的逻辑来选择分支并返回 task_id 或 task_ids 列表。

参数

context (airflow.utils.context.Context) – 传递给 execute() 的上下文字典

此条目是否有帮助?