airflow.providers.standard.operators.weekday

模組內容

類別

BranchDayOfWeekOperator

根據當天是星期幾,分支到兩個任務列表之一。

class airflow.providers.standard.operators.weekday.BranchDayOfWeekOperator(*, follow_task_ids_if_true, follow_task_ids_if_false, week_day, use_task_logical_date=False, **kwargs)[原始碼]

繼承自: airflow.operators.branch.BaseBranchOperator

根據當天是星期幾,分支到兩個任務列表之一。

有關如何使用此運算子的更多資訊,請參閱指南: BranchDayOfWeekOperator

範例(單日)

from airflow.operators.empty import EmptyOperator
from airflow.operators.weekday import BranchDayOfWeekOperator

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
from airflow.operators.weekday import BranchDayOfWeekOperator

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 | collections.abc.Iterable[str]) – 如果符合條件,要跟隨的 task_id、task_group_id 或 task_id 和/或 task_group_id 的列表。

  • follow_task_ids_if_false (str | collections.abc.Iterable[str]) – 如果**不**符合條件,要跟隨的 task_id、task_group_id 或 task_id 和/或 task_group_id 的列表。

  • week_day (str | collections.abc.Iterable[str] | airflow.utils.weekday.WeekDay | collections.abc.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,則使用系統的星期幾。

choose_branch(context)[原始碼]

選擇要執行哪個分支的抽象方法。

子類別應實作此方法,執行選擇分支所需的任何邏輯,並傳回 task_id 或 task_id 列表。

參數

context (airflow.utils.context.Context) – 傳遞給 execute() 的 Context 字典

這個條目有幫助嗎?