airflow.operators.branch

Branching operators.

Module Contents

Classes

BranchMixIn

Utility helper which handles the branching as one-liner.

BaseBranchOperator

A base class for creating operators with branching functionality, like to BranchPythonOperator.

class airflow.operators.branch.BranchMixIn(context=None)[source]

Bases: airflow.models.skipmixin.SkipMixin

Utility helper which handles the branching as one-liner.

do_branch(context, branches_to_execute)[source]

Implement the handling of branching including logging.

class airflow.operators.branch.BaseBranchOperator(pre_execute=None, post_execute=None, on_execute_callback=None, on_failure_callback=None, on_success_callback=None, on_retry_callback=None, on_skipped_callback=None, **kwargs)[source]

Bases: airflow.models.baseoperator.BaseOperator, BranchMixIn

A base class for creating operators with branching functionality, like to BranchPythonOperator.

Users should create a subclass from this operator and implement the function choose_branch(self, context). This should run whatever business logic is needed to determine the branch, and return one of the following: - A single task_id (as a str) - A single task_group_id (as a str) - A list containing a combination of task_ids and task_group_ids

The operator will continue with the returned task_id(s) and/or task_group_id(s), and all other tasks directly downstream of this operator will be skipped.

abstract 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()

execute(context)[source]

Derive when creating an operator.

Context is the same dictionary used as when rendering jinja templates.

Refer to get_template_context for more context.

Was this entry helpful?