airflow.operators.datetime

Module Contents

Classes

BranchDateTimeOperator

Branches into one of two lists of tasks depending on the current datetime.

Functions

target_times_as_dates(base_date, lower, upper)

Ensure upper and lower time targets are datetimes by combining them with base_date.

class airflow.operators.datetime.BranchDateTimeOperator(*, follow_task_ids_if_true, follow_task_ids_if_false, target_lower, target_upper, use_task_logical_date=False, use_task_execution_date=False, **kwargs)[source]

Bases: airflow.operators.branch.BaseBranchOperator

Branches into one of two lists of tasks depending on the current datetime.

For more information on how to use this operator, take a look at the guide: BranchDateTimeOperator.

True branch will be returned when datetime.datetime.now() falls below target_upper and above target_lower.

Parameters
  • follow_task_ids_if_true (str | Iterable[str]) – task id or task ids to follow if datetime.datetime.now() falls above target_lower and below target_upper.

  • follow_task_ids_if_false (str | Iterable[str]) – task id or task ids to follow if datetime.datetime.now() falls below target_lower or above target_upper.

  • target_lower (datetime.datetime | datetime.time | None) – target lower bound.

  • target_upper (datetime.datetime | datetime.time | None) – target upper bound.

  • use_task_logical_date (bool) – If True, uses task’s logical date to compare with targets. Execution date is useful for backfilling. If False, uses system’s date.

choose_branch(context)[source]

Abstract method to choose which branch to run.

Subclasses should implement this, running whatever logic is necessary to choose a branch and returning a task_id or list of task_ids.

Parameters

context (airflow.utils.context.Context) – Context dictionary as passed to execute()

airflow.operators.datetime.target_times_as_dates(base_date, lower, upper)[source]

Ensure upper and lower time targets are datetimes by combining them with base_date.

Was this entry helpful?