airflow.providers.standard.operators.weekday
¶
模块内容¶
类¶
根据当前日期分支到两个任务列表之一。 |
- 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]) – 如果满足条件,要跟踪的任务 ID、任务组 ID 或任务 ID 和/或任务组 ID 的列表。
follow_task_ids_if_false (str | collections.abc.Iterable[str]) – 如果不满足条件,要跟踪的任务 ID、任务组 ID 或任务 ID 和/或任务组 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
,则使用系统的星期几。