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.providers.standard.operators.branch.BaseBranchOperator

根據當前日期將流程分發到兩個任務列表之一。

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

示例(包含單個日期)

from airflow.providers.standard.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.providers.standard.utils.weekday import WeekDay
from airflow.providers.standard.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[原始碼]
follow_task_ids_if_false[原始碼]
week_day[原始碼]
use_task_logical_date = False[原始碼]
choose_branch(context)[原始碼]

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

子類應實現此方法,執行選擇分支所需的任何邏輯,並返回一個或多個 task_id。

引數:

context (airflow.sdk.definitions.context.Context) – 傳遞給 execute() 的上下文字典

本條目有幫助嗎?